1282 views|0 replies

6570

Posts

0

Resources
The OP
 

Providing information via pragmas [Copy link]

You can insert some specific syntax compilation directives into the code to tell the compiler some information about the code. Because the compiler always optimizes the code with the worst plan when it lacks information, if the programmer can provide some key information, it will greatly help the compiler make good decisions. The most commonly used ones are MUST_ITERATE and UNROLL. MUST_ITERATE: Provides some exact information about the number of loops: the minimum possible number of loops, the maximum possible number of loops, and the number of loops as multiples of a factor. Its usage syntax is as follows: When some parameters cannot be determined, it is allowed to be defaulted: UNROLL: The expansion directive tells the compiler that the loop code can be appropriately expanded. Its usage syntax is as follows: Before the expansion directive, it is also best to use the MUST_ITERATE directive to tell the compiler that the number of loops is a multiple of the expansion factor, so as to avoid generating extra code to handle abnormal situations, such as: There are two benefits of expansion: one is that it allows the compiler to use each computing unit more evenly; the other is that the compiler has more opportunities to use SIMD instructions. But one thing to note is that expansion will increase the size of the loop body. 4. Notes on loop optimization The key to loop optimization is to make the loop software pipelineable. For complex loops, such as nested loops, conditional branches inside loops, and function calls inside loops, the effectiveness of the compiler may be compromised. When the situation becomes too complex, the compiler might not be able to pipeline at all. The compiler only performs software pipelines on internal loops. Software pipelined loops can contain instrinsics, but not function calls. There must be no break and goto statements in the loop structure, and there must be no conditional termination instructions that cause the loop to exit early. The conditional code should be as simple as possible. In C64XX, when the conditional code requires more than 6 registers, the loop cannot be software pipelined. Avoid making the loop body too complex, which will result in insufficient register sets. If the life of a register is required to be too long, the code cannot be software pipelined. The loop structure should not contain code that changes the value of the loop counter.


This post is from Microcontroller MCU
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list