现在的编译器还需要手动展开循环吗,如何告诉编译器展开这个循环

I have the following loop that I am running on an ARM processor.

// pin here is pointer to some part of an array

for (i = 0; i < v->numelements; i++)

{

pe = pptr[i];

peParent = pe->parent;

SPHERE *ps = (SPHERE *)(pe->data);

pin[0] = FLOAT2FIX(ps->rad2);

pin[1] = *peParent->procs->pe_intersect == &SphPeIntersect;

fixifyVector( &pin[2], ps->center ); // Is an inline function

pin = pin + 5;

}

By the slow performance of the loop, I can judge that the compiler was unable to unroll this loop, as when I manually do the unrolling, it becomes quite fast. I think the compiler is getting confused by the pin pointer. Can we use restrict keyword to help the compiler here, or is restrict only reserved for function parameters? In general how can we tell the compiler to unroll it and don't worry about the pin pointer.

解决方案

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."

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值