CX51 用户手册----OPTIMIZE 伪指令

声明:

1、本翻译仅供个人学习使用,本人没有提供技术支持的义务,也不承担由此引发的任何后果。

2、请勿用于商业用途。

3、英文来自:http://www.keil.com/support/man/docs/c51/。

4、欢迎大家共同与我交流探讨(290207203@qq.com)。

OPTIMIZE Compiler Directive

Abbreviation

OT

Arguments

A decimal number between 0 and 11 enclosed in parentheses optionally followed by SIZEor SPEED to specify code size or execution speed emphasis.

Default

OPTIMIZE (8, SPEED)

µVision

Options — C51 — Code Optimization.

Description

The OPTIMIZE directive sets the optimization level and emphasis the Cx51 Compiler uses when generating object code.

Level Description
0 Constant Folding: The compiler performs calculations that reduce expressions to numeric constants, where possible. This includes calculations of run-time addresses.

Simple Access Optimizing: The compiler optimizes access of internal data and bit addresses in the 8051 system.

Jump Optimizing: The compiler always extends jumps to the final target. Jumps to jumps are eliminated.
1 Dead Code Elimination: Unused code fragments and artifacts are eliminated.

Jump Negation: Conditional jumps are closely examined to see if they can be streamlined or eliminated by the inversion of the test logic.
2 Data Overlaying: Data and bit segments suitable for static overlay are identified and internally marked. The BL51 Linker/Locator has the capability, through global data flow analysis, of selecting segments which can then be overlaid.
3 Peephole Optimizing: Redundant MOV instructions are removed. This includes unnecessary loading of objects from the memory as well as load operations with constants. Complex operations are replaced by simple operations when memory space or execution time can be saved.
4 Register Variables: Automatic variables and function arguments are located in registers when possible. Reservation of data memory for these variables is omitted.

Extended Access Optimizing: Variables from the IDATA, XDATA, PDATA and CODE areas are directly included in operations. Intermediate registers are frequently unnecessary.

Local Common Subexpression Elimination: The compiler detects multiple uses of the same expression or subexpression. The result of the first expression is saved and reused when possible. Superfluous expression calculations are eliminated from the code.

Case/Switch Optimizing: Code involving switch and case statements is optimized using jump tables or jump strings.

Simple Loop Optimizing: Program loops that fill a memory range with a constant are converted and optimized.
5 Global Common Subexpression Elimination: Identical subexpressions within a function are calculated only once when possible. The intermediate result is stored in a register and reused.
6 Loop Rotation: Program loops are rotated if the resulting program code is faster and more efficient. The loop expression of for and while loops is evaluated once at the top of the loop and then at the bottom of the loop. This optimization generates more code but speeds up execution.
7 Extended Index Access Optimizing: DPTR is used for register variables where appropriate. Pointer and array access are optimized for both execution speed and code size.
8 Common Tail Merging: When there are multiple calls to a single function, some of the setup code can be reused, thereby reducing program size.
9 Common Block Subroutines: Recurring instruction sequences are detected and converted into subroutines. The Cx51 Compiler rearranges code to obtain larger recurring sequences.
10 Rearrange Code (Linker Optimization): When detecting common block subroutines, code is rearranged to obtain larger recurring sequences.
11 Reuse of Common Exit Code (Linker Optimization): Identical exit sequences are reused. This may reduce the size of common block subroutines even further. This optimization level generates the most compact program code possible.

 Note

  • Each higher optimization level contains all of the characteristics of the preceding lower optimization level. For example, OPTIMIZE level 9 includes all optimizations of levels 0 to 8.
  • You may change the optimizer level on a function-by-function basis as needed. For example:
    #pragma OT(3)
    void funct_1 (void)
    {
    ...
    }
    
    #pragma OT(9)
    void func_2 (void)
    {
    ...
    }
    
See Also

OBJECTADVANCED

Example
C51 SAMPLE.C OPTIMIZE (9)

C51 SAMPLE.C OPTIMIZE (0)

#pragma ot(6, SIZE)

#pragma ot(size)


OPTIMIZE 编译器伪指令

缩写

OT

参数

0~11之间的任意一个整数,用括号括起来。可选地,后面可以跟一个 SIZE或 SPEED 指示强调代码大小或执行速度。

缺省

OPTIMIZE (8, SPEED)

µVision

Options — C51 — Code Optimization.

描述

OPTIMIZE 伪指令设置优化级别,并强调 Cx51 编译器生成目标代码时的使用方式。

级别 描述
0 常量折叠: 如有可能,编译器在计算时把表达式简化为数字常量,包括实时地址的计算。

简单访问优化: 在8051系统中,编译器优化内部数据和位地址的优化。

跳转优化: 编译器总是扩展跳转到最终目标,跳转到跳转忽略。
1 死代码消除: 未使用的代码段和块消除。

跳转忽略: 条件跳转被密切地检查,以查看它们是否被测试逻辑忽略。
2 数据覆盖: 适合静态覆盖的数据和位段相同并在内部标记。 BL51 链接器/定位器有能力通过全局数据流分析哪些段可以被覆盖。
3 窥孔优化: 多余的 MOV指令移除。这包括不必要的从存储器装载对象,也包括使用常量的装载操作。如果存储器空间或执行时间可以节省,复杂的操作被简单的操作替换。 
4 寄存器变量: 如果可能,自动变量和函数参数定位在寄存器中。保留在数据存储器中的这类变量被忽略。

扩展访问优化: 保存在 IDATA, XDATA, PDATA and CODE 区域的变量直接包含在操作中。中间的寄存器不需要。

局部公共子表达式消除: 编译器检测多次使用的同一个表达式或子表达式。第一个表达式的结果被保存并重复使用。多余的表达式计算从代码中消除。

Case/Switch 优化: 包含switch 和 case 语句的代码使用跳转表或跳转串优化。

简单循环优化: 填充一块存储器的程序循环转换为一个常量并优化。
5 全局公共子表达式取消: 如果可能,函数中相同的子表达式只计算一次。中间结果保存在寄存器中,并重复使用。
6 循环轮询: 如果生成的程序代码更快,更有效,程序循环轮询。for 和 while 循环中的循环表达式仅在顶层循环和底层循环计算一次。 这种优化增加了代码,但提高了执行速度。
7 扩展索引访问优化: 如果可能,DPTR 应用寄存器变量。指针和数组访问同时优化执行速度和代码大小。
8 公共代码合并: 当多次调用一个函数时,有些设置代码可以重复使用,以降低程序大小。
9 公共块子程序: 循环指令序列被检测,并转换为子程序。Cx51 编译器重新分配代码,以获得更大的循环序列。
10 程序安排代码 (链接器优化): 当检测到公共块子程序时,代码重新分配,以获得更大的循环序列。
11 重复使用公共退出代码 (链接器优化): 相同的退出序列重复使用。这可以进一步降低公共块子程序的大小。这个优化级别尽可能地生成最紧凑的程序代码。

 注意

  • 每个高优化级别包含所有低优化级别的属性。例如,9级优化包含之前的0~8级优化。
  • 用户可以根据需要改变每个函数的优化级别。例如:
    #pragma OT(3)
    void funct_1 (void)
    {
    ...
    }
    
    #pragma OT(9)
    void func_2 (void)
    {
    ...
    }
    
参考

OBJECTADVANCED

示例
C51 SAMPLE.C OPTIMIZE (9)

C51 SAMPLE.C OPTIMIZE (0)

#pragma ot(6, SIZE)

#pragma ot(size)



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值