原创 [ARM架构] Writing Loops Efficiently

2010-7-12 22:01 2170 1 1 分类: MCU/ 嵌入式
摘自
ARM System Developer’s Guide
Designing and Optimizing System Software
326d211b-a6eb-4b1d-9c3f-0a280ca81934.jpg

中文版
点击看大图

英文版的免费下载地址:
http://www.docstoc.com/docs/2844296/ARM-System-Developers-Guide
需要注册一下

Summary
Writing Loops Efficiently
■ Use loops that count down to zero. Then the compiler does not need to allocate
a register to hold the termination value, and the comparison with zero is free.
■ Use unsigned loop counters by default and the continuation condition i!=0 rather than
i>0. This will ensure that the loop overhead is only two instructions.
■ Use do-while loops rather than for loops when you know the loop will iterate at least
once. This saves the compiler checking to see if the loop count is zero.
■ Unroll important loops to reduce the loop overhead. Do not overunroll. If the loop
overhead is small as a proportion of the total, then unrolling will increase code size and
hurt the performance of the cache.
■ Try to arrange that the number of elements in arrays are multiples of four or eight. You
can then unroll loops easily by two, four, or eight times without worrying about the
leftover array elements.

文章评论0条评论)

登录后参与讨论
我要评论
0
1
关闭 站长推荐上一条 /2 下一条