ANTHONY ANTHONY - 8 months ago 71
Linux Question

How to use PREFETCHT0 Instruction in my C code?

I want to prefetch certain addresses (which are address of certain elements of a huge array) in my C program and see the effect of that on time taken.

The instruction about PREFETCH i found here PREFETCH0. But I am not aware of how to use it in C using inline assembly. It would be of great help if some body can give some idea how should I use this instruction with the address as argument, in C program.

Thank you.


Don't write it using inline assembly which would make the compiler's job harder. GCC has a built-in extension for prefetch you should use instead:

__builtin_prefetch(const void*)

This will generate code using the prefetch instructions of your target, but with more scope for the compiler to be smart about it.

See gcc docs for more details: