IAR 编译优化 #pragma optimize

在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、最高速优化

如果想设置优化速度到最高等级,则如下设置即可

#pragma optimize=speed high
int SmallAndUsedOften()
{
/* Do something here. */
}

2.3、禁用优化

如果需要针对某个函数禁用所有优化

/// @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++)
                {
                }
        }
}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值