編譯器keil的優(yōu)化選項(xiàng)針對ARM_第1頁
編譯器keil的優(yōu)化選項(xiàng)針對ARM_第2頁
編譯器keil的優(yōu)化選項(xiàng)針對ARM_第3頁
編譯器keil的優(yōu)化選項(xiàng)針對ARM_第4頁
編譯器keil的優(yōu)化選項(xiàng)針對ARM_第5頁
已閱讀5頁,還剩17頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、 HYPERLINK /yangtalent1206/article/details/8493120 編譯器_keil的優(yōu)化選項(xiàng)問題分類: HYPERLINK /yangtalent1206/article/category/680906 編譯器類2013-01-11 14:12280人閱讀 HYPERLINK /yangtalent1206/article/details/8493120 l comments 評論(0) HYPERLINK javascript:void(0); o 收藏 收藏 HYPERLINK /yangtalent1206/article/details/849312

2、0 l report o 舉報(bào) 舉報(bào) HYPERLINK /tag/details.html?tag=application t _blank application HYPERLINK /tag/details.html?tag=Application t _blank Application HYPERLINK /tag/details.html?tag=compilation t _blank compilation HYPERLINK /tag/details.html?tag=compiler t _blank compiler HYPERLINK /tag/details.html

3、?tag=optimization t _blank optimization HYPERLINK /tag/details.html?tag=performance t _blank performance HYPERLINK /tag/details.html?tag=Performance t _blank Performance最近發(fā)現(xiàn)在keil編譯的時(shí)候,出現(xiàn)莫名的問題,貌似代碼有被優(yōu)化掉的問題,后來查了下相關(guān)的資料,貌似懂了點(diǎn)。我選擇的是默認(rèn)的default優(yōu)化方式,上網(wǎng)看了下,默認(rèn)的是level2級別優(yōu)化,最后選擇level0就沒有問題了下面是網(wǎng)上找的資料,介紹了優(yōu)化功能介紹Ge

4、tting the Best Optimized Code for your Embedded ApplicationARM Compilation ToolsThe ARM Compilation Tools are the only compilation tool s co -developed with the ARM processors, and specificallydesigned to optimally support the ARM architecture. They are a result of 20 years of development, and are r

5、ecognized as theindustry -leading C and C+ compilation tools for the ARM, Thumb, and Thumb -2 instructions sets.The ARM Compilation tools consist of: The ARM Compiler, which enables you to compile C and C+ code. It is an optimizing compiler, and featurescommand - line options to enable you to contro

6、l the level of optimization Linker and Utilities, which assign addresses and lay out sections of code to form a final image A selection of libraries, including the ISO standard C libraries, and the MicroLIB C library which is optimized forembedded applications Assembler, which generates machine code

7、 instructions from ARM, Thumb or Thumb-2 assembly- level source code Compiler Options for Embedded Applications The ARM Compilation Tools include a number of compiler optimizations to help you best target your code for your chosenmicrocontroller device and application area. They can be accessed from

8、 within Vision by clicking on Project Options for Target.T he options described this document can be found on the Target an d C/C+ tabs of the Options for Targets dialog. MDK Compiler Optimizations Cross- Module Optimization takes information from a prior build and uses it to place UNUSED functions

9、into theirown ELF section in the corresponding object file. This option is also known as Linker Feedback, and requires you tobuild your application twice to take adv antage of it for reduced code size. Cross-Module Optimization has been shown to reduce code size, by removing unused functions from yo

10、ur application. Itcan also improve the performance of your application, by allowing modules to share inline code. The M icroLIB C libraryhas been optimized to reduce the size of embedded applications. It is a subset of the ISOstandard C runtime library, and offers a tradeoff between functionality an

11、d code size. Some of the standard C libraryfunctions such as memcpy() are slower, while some features of the default library are not supported. Unsupportedfeatures include: o Operating system functions e.g. abort(), exit(), time(), system(), getenv(), o Wide character and multi-byte support e.g. mbt

12、owc(), wctomb()o The stdio file I/O function, with the exception of stdin, stdout and stderr o Position-independent and thread -safe code Use the MicroLIB C library for applications where overall performance can be traded off against the need to reduce codesize and memory cost. Link- Time Code Gener

13、ation instructs the compiler to create objects in an intermediate format so that the linker canperform further code optimizations. This gives the code generator visibility into cross - file dependencies of all objectssimultaneously, allowing it t o apply a higher level of optimizations. Link -time c

14、ode generation can reduce code size, andallow your application to run faster. Optimization Levels can also be adjusted. The different levels of optimization allow you to trade off between the levelof debug information available in the compiled code, and the performance of the code. The following opt

15、imization levelsare available:o - O0 applies minimum optimizations. Most optimizations are switched off, and the code generated has the best debug view. o - O1 applies restricted optimization. For example, unused inline functions and unused static functions are removed. At this level of optimization

16、, thecompiler also applies automatic optimizations such as removing redundant code and re -ordering instructions s oas to avoid an interlock situation. The code generated is reasonably optimized, with a good debug view. o - O2 applies high optimization (This is the default setting). Optimizations ap

17、plied at this level take advantage of ARMs in-depth knowledge of the processor architecture,to exploit processor -specific behavio r of the given target. It generates well optimized code, but with limiteddebug view. o - O3 applies th e most aggressive optimization. The optimization is in accordance

18、with the users Ospace/- Otime choice . By default, multi - file compilation isenabled, which leads to a longer compile time, but gives the highest levels of optimization. The Optimize for Time checkbox causes the compiler to optimize with a greater focus on achieving the bestperformance when checked

19、 ( - O time) or the smallest code siz e when unchecked ( -O space). Unchecking Optimize for Time selects the Ospace option which instructs the compiler to perform optimizations toreduce the image size at the expense of a poss ible increase i n execution time. F or example, using out -of -line functi

20、oncalls instead of inline code for large structure copies. This is the default option. When running the compiler from thecommand line, this option is invoked using -OspaceChecking Optimize for Time selects the Otime option which instructs the compiler to optimize the code for the fastestexecution ti

21、me, at the risk of an increase in the image size. It is recommended that you compile the time -critical parts ofyour code with Otime, and the rest us ing the Ospace directive . Split Load and Store Multiples instructs the compiler to split LDM and STM instructions involving a large number ofregister

22、s into a series of loads/stores of fewer multiple registers. This means that an LDM of 16 registers can be split into4 separate LDMs of 4 registers each. This option helps to reduce the interrupt latency on ARM systems which do nothave a cache or write buffer, and systems which use zero - wait state

23、 32-bit memory. For example, the ARM7 and ARM9 processor s t ake can only take an exception on an instruction boundary. If anexception occurs at the start of an LDM of 16 registers in a cacheless ARM7 /ARM9 system, the system will finishmaking 16 accesses to memory before taking the exception. Depen

24、ding on the memory arbitration system, this can resultin a very high interrupt latency. Breaking the LDM into 4 individual LDMs for 4 registers means that the processor willtake the exception after loading a maximum of 4 registers, thereby greatly reducing the interrupt latency.Selecting this option

25、 improves the overall performance of the system. The One ELF Section per Function option tells the compiler to put all functions into their own individual ELFsections. This allows the linker to remove unused functions. An ELF code section typically contains the code for a number of functions. The li

26、nker is normally only able to removeunused ELF sections, not unused functions. An ELF section can only be removed if all its contents are unused.Therefore, splitting each function into its own ELF section allows the compiler to easily identify which ones are unused,and remove them. Selecting this op

27、tion increases the time required to compile your code, but results in improved performance . The combination of options applied will depend on your optimization goal whether you are optimizing for smallest codesize, or best performance.The next section illustrates the best optimization options for e

28、ach of these goals.Optimizing for Smallest Code SizeTo optimize your code for the smallest size, the best options to apply are: The MicroLIB C library Cross- module optimization Optimization level 2 ( -O2)Compile the Measure example without any optimizations The Measure example uses analog and digit

29、al inputs to simulate a data l ogger. File - Open ProjectC: Keil ARMBoards Keil MCBSTM32MeasureMeasure.uv2Click the Options for Target button In the Target tab: Uncheck Cross- Module Optimization Uncheck Use MicroLIB Uncheck Use Link- Time Code Generation In the C/C+ tab: Set Optimization Level to Z

30、eroThen click OK to save your changes. Project Build target Without any compiler optimizations applied, the initial code size is 13,656 Bytes.MDK Compiler Optimizations Optimize the Measur e example for Size Apply the compiler optimizations in turn, and re-compile each time to see their effect in re

31、ducing the code size for theexample. Options for Target Target tab: Use the MicroLIB C library Options for Target Target tab: Use cross - mod ule optimization - Remember to compile twice Options for Target C/C+ tab: Enable Optimization level 2 ( -O2)Optimization Applied Compile Size Size Reduction I

32、mprovement MicroLIB C library 8,960 Bytes 4,696 Bytes 34% smallerCross- Module Compilation 13,500 Bytes 156 Bytes 1.1% smallerOptimization level O2 12,936 Bytes 720 Bytes 5.3% smallerAll 3 optimization options 8,116 Bytes 5,540 Bytes 40.6% smaller Applying all the optimizations will reduce the code

33、size down to 8,116 Bytes.The fully optimized code is 5,540 Bytes smaller, a total code size reduction of 40.6%MDK Compiler Optimizations Optimizing for Best PerformanceTo optimize your code for performance, the best options to apply are: Cross- module optimization Optimization level 3 ( -O3) Optimiz

34、e for timeRun the Dhrystone benchmark without any optimizationsThe Dhrystone benchmark is used to measure and compare the performance of different computers, or the efficiency of thecode generated for the same computer by different compilers. File Open Project C: Keil ARMExamples DHRY DHRY.uv2 Click

35、 the Options for Target button Turn off optimization settings in the Target and C/C+ tabs , then click OK Project Build target Enter D ebug mode View Se rial Windows UART #1 Open the UART #1 window View Analysis Windows Performance Analyzer Open the Performance Analyzer Debug Run Start running the a

36、pplication When prompted: Enter 50000 in the UART#1 window and press EnterIn the Performance Analyzer window, note that The drhy_1 loop took 2.829s The dhry_2 took 2.014sIn the UAR T #1 window, note that It took 138.0 ms for 1 run through Dhrystone The application is executing 7246.4 Dhrystones per

37、second Optimize the Dhrystone example for PerformanceRe-compile the example with all three of the following optimizations applied: Options f or Target Target tab: Cross - module optimization Remember to compile twice Options for Target C/C+ tab: Optimization level 3 ( -O3) Options for Target C/C+ ta

38、b: Optimize for TimeRe-run the application, and examine the performance. Measurement Without optimizations With Optimizations Improvement dhry_1 2.829s 1.695s 40.1% fasterdhry_2 2.014s 1.011s 49.8% fasterMicroseconds for 1 runthrough Dhrystone138.0 70 49.3% fasterDhrystones per second 7246.4 14,285.

39、7 97.1% more The fu lly optimize d code achieves approximate ly 2x the performance of the un -optimized code.SummaryThe ARM Compilation Tools offer a range of options to apply when compiling your code. These options can be combined tooptimize your code for best performance, for smallest code size, o

40、r for any performance point between these two extremes, tobest suit your targeted microcontroller device and market. When optimizing your code, MDK- ARM makes it easy and convenient to measure the effect of the different optimizationsett ings on your application. The code size is clearly displayed a

41、fter compilation, and a range of analysis tools such as thePerformance Analyzer enable you to measure performance. The optimization options in the ARM Compilation Tools, together with the easy- to - use analysis tools in MDK - ARM, helpyou to easily optimize your application to meet your specific re

42、quirements.獲得最佳優(yōu)化的代碼為您的嵌入式應(yīng)用ARM編譯工具ARM編譯工具是唯一的編譯工具與ARM處理器共同開發(fā),并專門最佳支持ARM架構(gòu)。他們是20多年的發(fā)展,被確認(rèn)為業(yè)界領(lǐng)先的C和C編譯工具的手臂,拇指和拇指-2指令集。ARM編譯工具包括:ARM編譯器,它使您能夠編譯C和C代碼。這是一個(gè)優(yōu)化的編譯器,功能命令 - 行選項(xiàng),使您能夠控制的優(yōu)化級別連接器和實(shí)用程序,分配地址和代碼段,形成最終的圖像庫的選擇,包括ISO標(biāo)準(zhǔn)C庫,以及新增加的microlib這是優(yōu)化的C庫嵌入式應(yīng)用匯編器,生成機(jī)器代碼指令的ARM,Thumb或Thumb-2匯編級源代碼用于嵌入式應(yīng)用的編譯器選項(xiàng)ARM編譯

43、工具包括編譯器優(yōu)化,以幫助您最好針對您的代碼,您所選擇的一些微控制器的設(shè)備和應(yīng)用領(lǐng)域。他們可以從Vision訪問點(diǎn)擊項(xiàng)目 - 目標(biāo)選項(xiàng)。他選擇本文檔描述的目標(biāo),C / C + +目標(biāo)“對話框的選項(xiàng)標(biāo)簽上可以找到。MDK編譯優(yōu)化跨模塊優(yōu)化信息從之前的構(gòu)建,并使用它來將未使用的功能集成到他們相應(yīng)的對象文件的ELF節(jié)。該選項(xiàng)也被稱為鏈接器反饋,并且需要您在建立你的應(yīng)用程序,兩次采取副詞antage的減少代碼大小。跨模塊優(yōu)化已經(jīng)證明,以減少代碼大小,從應(yīng)用程序中刪除未使用的功能。它還可以提高應(yīng)用程序的性能,允許內(nèi)嵌代碼模塊共享。的M icroLIB的C庫已優(yōu)化的嵌入式應(yīng)用,以減少大小。它的一個(gè)子集的I

44、SO標(biāo)準(zhǔn)C運(yùn)行時(shí)庫,并提供了功能和代碼大小之間的權(quán)衡。有些標(biāo)準(zhǔn)C庫memcpy()函數(shù)的功能,如速度較慢,而默認(rèn)的庫不支持某些功能。不支持功能包括:o操作系統(tǒng)的功能,例如退出中止(),(),(),(),用getenv()o寬字符和多字節(jié)支持,例如wctomb mbtowc()()stdio的文件I / O功能,除標(biāo)準(zhǔn)輸入,標(biāo)準(zhǔn)輸出和標(biāo)準(zhǔn)錯(cuò)誤O位置獨(dú)立的線程安全的代碼使用新增加的microlib C庫的整體性能的應(yīng)用場合需要減少代碼可以進(jìn)行交易抵銷大小和內(nèi)存成本。鏈接時(shí)代碼生成指示編譯器創(chuàng)建的對象中的中間格式,使連接器可以進(jìn)行進(jìn)一步的優(yōu)化代碼。這使代碼生成器的可視性 - 文件中的所有對象的依賴同

45、時(shí),以申請更高級別的優(yōu)化。鏈接時(shí)代碼生成,可以減少代碼大小,讓應(yīng)用程序運(yùn)行得更快。優(yōu)化級別,也可以進(jìn)行調(diào)整。不同層次的優(yōu)化,讓您取舍之間的水平調(diào)試信息可以在編譯的代碼,代碼的性能。下面的優(yōu)化水平可供選擇:O - O0適用最低的優(yōu)化。最優(yōu)化關(guān)閉,生成的代碼具有最佳的調(diào)試視圖。O - O1適用于受限制的優(yōu)化。例如,未使用的內(nèi)聯(lián)函數(shù)和未使用的靜態(tài)函數(shù)將被刪除。在這個(gè)層面上的優(yōu)化,編譯器也適用于自動(dòng)優(yōu)化,如去除冗余代碼,并重新排序指令,所以以避免的聯(lián)鎖情況。生成的代碼優(yōu)化合理,具有良好的調(diào)試視圖。O - O2適用于高優(yōu)化(這是默認(rèn)設(shè)置)。在這個(gè)級別應(yīng)用的優(yōu)化利用ARM的處理器架構(gòu)的深入了解,利用給定的

46、目標(biāo)的特定處理器的行為。它產(chǎn)生很好的優(yōu)化代碼,但有限的調(diào)試視圖。鄰 - O3適用于日最積極的優(yōu)化。的優(yōu)化是根據(jù)與用戶的的 - Ospace / - Otime進(jìn)行選擇。默認(rèn)情況下,多 - 文件匯編啟用,這導(dǎo)致更長的編譯時(shí)間,但給出了最高級別的優(yōu)化。時(shí)間“復(fù)選框的優(yōu)化,使編譯器將更加注重優(yōu)化達(dá)到最佳性能檢查( - O時(shí)間)或最小的代碼尺寸未選中時(shí)(-O空間等)。取消選中優(yōu)化時(shí)間選擇 - Ospace編譯選項(xiàng)指示編譯器執(zhí)行優(yōu)化,以降低圖像的大小,以犧牲一個(gè)POSS IBLE的執(zhí)行時(shí)間增加。 F或例如,使用在線功能大型結(jié)構(gòu)副本,而不是內(nèi)聯(lián)代碼調(diào)用。這是默認(rèn)的選項(xiàng)。當(dāng)運(yùn)行編譯器命令行中,該選項(xiàng)被調(diào)用使

47、用的-Ospace檢查時(shí)間的優(yōu)化選擇的 - Otime選項(xiàng)指示編譯器優(yōu)化代碼以最快的執(zhí)行時(shí)間,圖像尺寸增加的風(fēng)險(xiǎn)。建議您編譯時(shí)間的關(guān)鍵部分您的代碼 - Otime時(shí),的其余我們ING的 - Ospace指令。拆分負(fù)載和存儲倍數(shù)指示編譯器LDM和STM指令涉及了大量的分割一系列的寄存器加載/存儲多個(gè)寄存器較少。這意味著,可以分割成16個(gè)寄存器的LDM4個(gè)獨(dú)立的4個(gè)寄存器的LDM。這個(gè)選項(xiàng)有助于減少中斷延遲的ARM系統(tǒng)上不有一個(gè)緩存或?qū)懭刖彌_區(qū),系統(tǒng)使用零等待狀態(tài) - 32位內(nèi)存。例如,ARM7和ARM9處理器ST阿克只能采取一個(gè)指令邊界上的一個(gè)例外。如果異常發(fā)生時(shí)的LDM的開始的16個(gè)寄存器,在

48、沒有高速緩存的ARM7 / ARM9系統(tǒng),該系統(tǒng)將完成16的內(nèi)存訪問異常。根據(jù)存儲器仲裁制度,這可能會(huì)導(dǎo)致在一個(gè)非常高的中斷延遲。也就是說處理器將打破4個(gè)寄存器分為4個(gè)獨(dú)立的LDM LDM采取異常后最多可裝載4個(gè)寄存器,從而大大降低了中斷延遲。選擇此選項(xiàng)可提高系統(tǒng)的整體性能。一個(gè)ELF節(jié)每個(gè)功能選項(xiàng)告訴編譯器將所有功能集成到自己的個(gè)人ELF的章節(jié)。這允許鏈接器刪除未使用的功能。一個(gè)ELF代碼段通常包含多項(xiàng)功能的代碼。鏈接器通常只能夠刪除未使用的ELF節(jié),而不是未使用的功能。一個(gè)ELF節(jié)只能所有內(nèi)容都被刪除,如果未使用。因此,每個(gè)功能拆分到它自己的ELF節(jié)使編譯器可以很容易地識別哪些是未使用的,

49、并刪除它們。選擇此選項(xiàng)會(huì)增加編譯代碼所需的時(shí)間,但在提高性能的結(jié)果。應(yīng)用選項(xiàng)的組合將取決于你的優(yōu)化目標(biāo) - 無論你是最小的代碼優(yōu)化的大小,或者最佳的性能。下一節(jié)將說明這些目標(biāo)的最優(yōu)化選擇。最小的代碼大小優(yōu)化要優(yōu)化你的代碼的最小尺寸,適用的最佳選擇是:新增加的microlib C庫跨模塊優(yōu)化優(yōu)化級別2(O2)沒有任何優(yōu)化編譯測量示例測量例如使用模擬數(shù)據(jù)升ogger的模擬和數(shù)字輸入。“文件” - “打開項(xiàng)目”C: KEIL ARM 板 KEIL MCBSTM32 測量 Measure.uv2上單擊“目標(biāo)”選項(xiàng)按鈕“在“目標(biāo)”選項(xiàng)卡:取消選中“跨模塊優(yōu)化取消使用microlib中取消選中“使用鏈接時(shí)

50、代碼生成在C / C + +選項(xiàng)卡:優(yōu)化級別設(shè)置到零然后點(diǎn)擊“確定”保存更改。項(xiàng)目 - 構(gòu)建目標(biāo)沒有任何編譯器優(yōu)化應(yīng)用,最初的代碼大小是13,656字節(jié)。MDK編譯優(yōu)化尺寸優(yōu)化的MEASUR例子反過來,編譯器優(yōu)化應(yīng)用并重新編譯每次看他們的效果,減少代碼大小例子。目標(biāo)選項(xiàng)“ - ”目標(biāo)“選項(xiàng)卡:使用新增加的microlib C庫目標(biāo)選項(xiàng)“ - ”目標(biāo)“選項(xiàng)卡:使用交叉 - MOD ULE優(yōu)化 - 請記住,兩次編譯目標(biāo)選項(xiàng) - C / C選項(xiàng)卡:啟用優(yōu)化級別2(O2)優(yōu)化應(yīng)用編譯尺寸大小減少改善microlib中C庫8,960字節(jié)4,696字節(jié)小34跨模塊編譯13,500字節(jié)156字節(jié)小1.1優(yōu)化

51、級別 - O2 12,936字節(jié)720字節(jié)小5.3所有的優(yōu)化選項(xiàng)8,116字節(jié)5,540字節(jié)小40.6應(yīng)用的所有優(yōu)化將會(huì)減少代碼大小8,116字節(jié)。全面優(yōu)化的代碼是5,540字節(jié)小,總的代碼大小減少40.6MDK編譯優(yōu)化優(yōu)化最佳性能要優(yōu)化你的代碼的性能,最好的選擇,適用于:跨模塊優(yōu)化優(yōu)化級別3(O3)優(yōu)化時(shí)間沒有任何優(yōu)化,運(yùn)行Dhrystone基準(zhǔn)Dhrystone基準(zhǔn)是用來衡量和比較不同的計(jì)算機(jī)的性能或效率的由不同的編譯器生成的代碼在同一臺計(jì)算機(jī)?!拔募?- “打開項(xiàng)目”C: KEIL ARM 示例 DHRY DHRY.uv2的單擊“目標(biāo)”選項(xiàng)按鈕“關(guān)閉優(yōu)化設(shè)定目標(biāo)和C / C + +選項(xiàng)

52、卡,然后單擊“確定”項(xiàng)目 - 構(gòu)建目標(biāo)輸入D ebug模式視圖 - SE現(xiàn)實(shí)的Windows - UART1打開UART1窗口景觀 - 分析的Windows - 性能分析器打開性能分析器調(diào)試“ - ”運(yùn)行“開始運(yùn)行的應(yīng)用程序當(dāng)系統(tǒng)提示:在UART1窗口中輸入50000,然后按Enter在性能分析器窗口,請注意drhy_1的循環(huán)用了2.829sdhry_2了2.014s在阿聯(lián)T1窗口,請注意,花了138.0毫秒1通過運(yùn)行Dhrystone的應(yīng)用程序執(zhí)行每秒7246.4根據(jù)Dhrystones性能優(yōu)化Dhrystone示例重新編譯應(yīng)用下列優(yōu)化所有三個(gè)例子:選項(xiàng)f或目標(biāo) - 目標(biāo)“選項(xiàng)卡: - 跨模

53、塊優(yōu)化 - 記住兩次編譯目標(biāo)選項(xiàng) - C / C標(biāo)簽:優(yōu)化級別3(O3)目標(biāo) - C / C標(biāo)簽選項(xiàng):優(yōu)化時(shí)間重新運(yùn)行應(yīng)用程序,并檢查其性能。沒有優(yōu)化優(yōu)化改進(jìn)的測量快dhry_1 2.829s 1.695s 40.1快dhry_2 2.014s 1.011s 49.8微秒1運(yùn)行通過Dhrystone的快138.0 70 49.3根據(jù)Dhrystones每秒7246.4 14,285.7 97.1福LLY優(yōu)化二維碼達(dá)到近似兩倍的性能未優(yōu)化的代碼??偨Y(jié)ARM編譯工具提供一系列的選項(xiàng)編譯代碼時(shí)適用。這些選項(xiàng)可以組合優(yōu)化你的代碼以獲得最佳性能,最小的代碼大小,或在這兩個(gè)極端之間的任何性能的角度,最適合

54、您的針對性的單片機(jī)和市場。當(dāng)MDK-ARM優(yōu)化你的代碼,使得它容易和方便地測量了不同的優(yōu)化效果SETT INGS您的應(yīng)用程序。在編譯后的代碼大小清楚地顯示,一系列的分析工具,如性能分析器允許你來衡量績效。ARM編譯工具的優(yōu)化選項(xiàng),再加上容易 - 在MDK使用分析工具 - ARM,幫助您可以輕松地優(yōu)化你的應(yīng)用程序,以滿足您的特定需求。級別說明0常數(shù)合并:編譯器預(yù)先計(jì)算結(jié)果,盡可能用常數(shù)代替表達(dá)式。包括運(yùn)行地址計(jì)算。優(yōu)化簡單訪問:編譯器優(yōu)化訪問8051系統(tǒng)的內(nèi)部數(shù)據(jù)和位地址。跳轉(zhuǎn)優(yōu)化:編譯器總是擴(kuò)展跳轉(zhuǎn)到最終目標(biāo),多級跳轉(zhuǎn)指令被刪除。1死代碼刪除:沒用的代碼段被刪除。拒絕跳轉(zhuǎn):嚴(yán)密的檢查條件跳轉(zhuǎn),

55、以確定是否可以倒置測試邏輯來改進(jìn)或刪除。2數(shù)據(jù)覆蓋:適合靜態(tài)覆蓋的數(shù)據(jù)和位段被確定,并內(nèi)部標(biāo)識。BL51連接/定位器可以通過全局?jǐn)?shù)據(jù)流分析,選擇可被覆蓋的段。3窺孔優(yōu)化:清除多余的MOV指令。這包括不必要的從存儲區(qū)加載和常數(shù)加載操作。當(dāng)存儲空間或執(zhí)行時(shí)間可節(jié)省時(shí),用簡單操作代替復(fù)雜操作。KEIL C 優(yōu)化詳細(xì)分析2011-01-26|閱:818轉(zhuǎn):9| HYPERLINK http:/www.360do/content/11/0126/14/2379862_89135875.shtml 分享Keil C51總線外設(shè)操作問題的深入分析 閱讀了單片機(jī)與嵌入式系統(tǒng)應(yīng)用2005年第10期雜志經(jīng)驗(yàn)交流欄

56、目的一篇文章Keil C51對同一端口的連續(xù)讀取方法(原文)后,筆者認(rèn)為該文并未就此問題進(jìn)行深入準(zhǔn)確的分析 文章中提到的兩種解決方法并不直接和簡單。筆者認(rèn)為這并非是Keil C51中不能處理對一個(gè)端口進(jìn)行連續(xù)讀寫的問題,而是對Kei1 C51的使用不夠熟悉和設(shè)計(jì)不夠細(xì)致的問題,因此特撰寫本文。 本文中對原文提到的問題,提出了三種不同于原文的解決方法。每種方法都比原文中提到的方法更直接和簡單,設(shè)計(jì)也更規(guī)范。(無意批評,請?jiān)淖髡咭娬?1 問題回顧和分析 原文中提到:在實(shí)際工作中遇到對同一端口反復(fù)連續(xù)讀取,Keil C51編譯并未達(dá)到預(yù)期的結(jié)果。原文作者對C編譯出來的匯編程序進(jìn)行分析發(fā)現(xiàn),對同一端

57、口的第二次讀取語句并未被編譯。但可惜原文作者并未分析沒有被編譯的原因,而是匆忙地采用一些不太規(guī)范的方法試驗(yàn)出了兩種解決辦法。 對此問題,翻閱Keil C51的手冊很容易發(fā)現(xiàn):KeilC51的編譯器有一個(gè)優(yōu)化設(shè)置,不同的優(yōu)化設(shè)置,會(huì)產(chǎn)生不同的編譯結(jié)果。一般情況缺省編譯優(yōu)化設(shè)置被設(shè)定為8級優(yōu)化,實(shí)際最高可設(shè)定為9級優(yōu)化:1. Dead code elimination。2.Data overlaying。3.Peephole optimization。4.Register variables。5.Common subexpression elimination。6.Loop rotation。7.

58、Extended Index Access Optimizing。8.Reuse Common Entry Code。9.Common Block Subroutines。 而以上的問題,正是由于Keil C51編譯優(yōu)化產(chǎn)生的。因?yàn)樵谠某绦蛑袑⑼庠O(shè)地址直接按如下定義:unsigned char xdata MAX197 _at_ 0 x8000 采用_at_將變量MAX197定義到外部擴(kuò)展RAM 指定地址0 x8000。因此,Keil C51優(yōu)化編譯理所當(dāng)然認(rèn)為重復(fù)讀第二次是沒有用的,直接用第一次讀取的結(jié)果就可以了,因此編譯器跳過了第二條讀取語句。至此,問題就一目了然了。2 解決方法由以上分析很容易就能提出很好的解決辦法。21 最簡單最直接的辦法 程序一點(diǎn)都不用修改,將Keil C51的編譯優(yōu)化選擇設(shè)置為0(不優(yōu)化)就可以了。選擇project窗口的Target,然后打開“Options for Target”設(shè)置對話框,選擇“C5

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論