开发者

Can C compiler prefetch data around the call?

开发者 https://www.devze.com 2023-01-26 18:50 出处:网络
Is it possible to good C compiler with high optimization enabled to optimize code with prefetches and to place prefetches before some function call:

Is it possible to good C compiler with high optimization enabled to optimize code with prefetches and to place prefetches before some function call:

struct *abc;
//...

function_first(&(abc->field1));
abc->field2= abc->field3+ abc->field4 + abc->field5 + ...; 
// a lot work on struct fields
function_second(&(abc->field1))

So, can code after compiler optimization to have a prefetches for abc fields and move it higher than function_first() call, like this:

struct *abc;
//...

__prefetch(abc->field2);__prefetch(abc->field5);
function_first(&(abc->field1));
abc->field2= abc->field3+ abc->field4 + abc->field5 + ...; 
// a lot work on struct fields
function_second(&(abc->field1))

The function function_first() can be annotated as clean (have no side-effects on abc fields other than field1), or the programm can be compiled in whole-program opti开发者_Go百科mization (-ipo /Qipo for intel), where compiler can check, what function_first do.

UPDATE: without calls the prefetches are possible, but this question is about mixing calls and prefetches

Thanks.


Yes, Intel's ICC compiler can do this (*). It's debatable whether it actually makes any difference to performance though.

(*) See the -opt-prefetch=n switch.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号