Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write cpu clock prefetch code

Shulou Source: shulou.com Published: 2022-06-03 07:42:31 10月02日 Update

This article mainly explains "how to write cpu clock prefetch code". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to write cpu clock prefetch code".

Test the effect of prefetching and always check the effect with CPU. According to the experiment, it is found that the prefetching address works better at about ten lines of code before the address is used.

The code is as follows:

# include

# define MAX_LEN 1000000

Static inline void prefetchnta (void * addr) / / prefetch part

{

_ _ asm__ ("movl% 0,% eax":: "a" (addr))

_ _ asm__ (".byte 0x0f, 0x18, 0x00")

}

Inline unsigned long long GetCPUTickCount ()

{

Unsigned long high42 = 0

Unsigned long low32 = 0

_ _ asm__ ("RDTSC": "= a" (low32), "= d" (high42))

Unsigned long long counter = high42

Counter = (counter

Tags: Code clock effect learning content address that is ideas situations articles more knowledge knowledge points articles followers parts questions ten lines practice experiments Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Tech Info Apple NVidia Docker