How to tell the compiler to unroll this loop [duplicate]

落爺英雄遲暮 提交于 2019-12-08 19:17:33
Robert Prior

To tell gcc to unroll all loops you can use the optimization flag -funroll-loops.

To unroll only a specific loop you can use:

__attribute__((optimize("unroll-loops")))

see this answer for more details.

Edit

If the compiler cannot determine the number of iterations of the loop upon entry you will need to use -funroll-all-loops. Note that from the documentation: "Unroll all loops, even if their number of iterations is uncertain when the loop is entered. This usually makes programs run more slowly."

If you extent pptr size by one, you can use the pld instruction.

  __asm__ __volatile__("pld\t[%0]" :: "r" (pptr[i+1]));

Or alternatively you may need to pre-load the next peParent and SPHERE *ps. The loop overhead on an ARM is very small. It is unlikely that un-rolling the loop will be a significant benefit. There are no loop variable constants. It is more likely that the compiler's scheduler is able to fetch advanced data before it is used when you have un-rolled the loop.

You have not presented all of the code to see the data dependencies. There maybe other variables that would benefit from being pre-loaded. Giving a complete example would probably help everyone answer your question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!