在IAR工具菜单栏中 点击 【help】-> 【Serach】 搜索optimize
说明:单独指定的优化等级优先级高于编译器统一指定的优化。
1、格式
#pragma optimize=[goal][level][vectorize][disable]
Parameters
goal |
Choose between: size, optimizes for size balanced, optimizes balanced between speed and size speed, optimizes for speed. no_size_constraints, optimizes for speed, but relaxes the normal restrictions for code size expansion. |
level |
Specifies the level of optimization—choose between none, low, medium, or high. |
vectorize |
Enables generation of NEON vector instructions. |
disable |
Disables one or several optimizations (separated by spaces). Choose between: no_code_motion, disables code motion no_cse, disables common subexpression elimination no_inline, disables function inlining no_relaxed_fp, disables the language relaxation that optimizes floating-point expressions more aggressively no_tbaa, disables type-based alias analysis no_scheduling, disables instruction scheduling. no_vectorize, disables generation of NEON vector instructions no_unroll, disables loop unrolling |
2、Example
2.1、速度和空间优化
#pragma optimize=speed
int SmallAndUsedOften()
{
/* Do something here. */
}
#pragma optimize=size
int BigAndSeldomUsed()
{
/* Do something here. */
}
2.2、最高速优化
如果想设置优化速度到最高等级,则如下设置即可文章来源:https://www.toymoban.com/news/detail-684705.html
#pragma optimize=speed high
int SmallAndUsedOften()
{
/* Do something here. */
}
2.3、禁用优化
如果需要针对某个函数禁用所有优化文章来源地址https://www.toymoban.com/news/detail-684705.html
/// @brief 延时us级别 实测误差 1us > 1.192us
/// @param us 延时时间
#pragma optimize = none //防止优化
void sleep_us(uint32_t us)
{
for (size_t i = 0; i < us; i++)
{
for (size_t j = 0; j < 11; j++)
{
}
}
}
到了这里,关于IAR 编译优化 #pragma optimize的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!