ログイン/登録
ヒント:複数の語句はコンマで区切ってください
Date
入力例:06/28/2022
Date
入力例:06/28/2022
Japan (日本語)
Global
China (简体中文)
Japan (日本語)
Korea (한국어)
Taiwan (繁體中文)
TI training & videos >
Applications & designs
Live training
Products
Tools & software
Toggle navigation
ヒント:複数の語句はコンマで区切ってください
Date
入力例:06/28/2022
Date
入力例:06/28/2022
Global
China (简体中文)
Japan (日本語)
Korea (한국어)
Taiwan (繁體中文)
メール
25 Functions for 25 Cents - Code Optimization & Resources
Now we will talk about some code optimization tips and tricks. The main control of the compiler optimization is through the optimization settings accessible within the IDE. The settings allow the user to select how aggressive they want the compiler to apply optimization, and the desired balance of optimizing for code size versus execution speed. In CCS, the optimization settings are found in project, properties, build, MSP430 compiler, and then optimization. There are two main optimization settings, optimization level, and speed versus size tradeoffs. The optimization level determines what types of optimizations the compiler is allowed to make. Speed versus size settings tell the compiler if tradeoffs should be made more in favor of speed or size, with zero being optimizing with the most focus on size, and level 5 being the most focused on speed. Settings between 0 and 5 instruct the compiler to take a more balanced approach. CCS provides a tool called the optimizer assistant, which is found under view, and then optimizer assistant, that can be used to decide the optimal set of compiler settings for a particular project to fit in its target device. The user selects which build option to vary, either speed versus size or optimization level. Then analysis then runs varying the selected build option accordingly. The other build option uses whatever is currently in the project settings and remains constant throughout the test. For example, if the tool varies the size versus speed setting, it uses whichever optimization level is currently selected in the project settings for all of the builds. The optimizer assistant displays the code size for the different settings. Red indicates if the code cannot fit in the selected device for the project. Yellow indicates that the code fits in the device, but a better option is available. And green indicates the recommended option for best execution speed performance while still fitting into the target device memory. The check mark indicates the current selection in the project settings. Controlling global variable initialization to save code space involves both modifications to user code, and using some compiler settings available in the IDE to tell the compiler not to automatically initialize the variables. First, move the initialization of the global variables into main. In the example, there are only two global variables, RX data and TX data, that are both initialized. The picture shows an example of moving the initialization for these variables to main. By default, projects built in the EABI format automatically initialize any uninitialized global variables to 0. This is to protect users from using a variable before it has a real value in it, which would cause a read of random values from RAM. However, as long as all global variables are initialized before usage, this problem does not occur. Because the code performs this initialization in main, zero initialization can be turned off. To disable zero initialization in CCS, click project, properties, MSP430 linker, advanced options, miscellaneous, and set the zero initialization EFL uninitialized section's options to off. While the C compiler can do a lot to optimize code for size, there are also things the user can do when writing code to help ensure smaller build size. Some things are essentially hand optimizations, while others provide hints to the compiler about properties of the code in ways that it is allowed to safely optimize it. Some of the hand optimizations include using the smallest possible type for variables and constants, avoiding multiply and divides wherever you can, use Word access to CPU registers, and writing to CPU registers only once. Using intrinsics will provide the compiler with additional information about the code allowing it to make further optimizations. Some examples of these intrinsics are the even in range intrinsic and the low power mode intrinsic. For more information about the 25 functions for $0.25, check out the links to the blog and tech notes, ebook, code examples, and video series. Thank you, and I hope you enjoyed this presentation.
説明
2018年 4月 27日
Learn how to hand optimize code, utilize compiler IDE settings, and find 25 Functions for 25 Cents resources
追加情報
Learn more about TI Microcontroller solutions
関連コース/イベント
08:45
Getting Started with InstaSPIN-FOC
11:08
Input and output limitations - Lab
13:47
What specifications to look for when designing power supplies for SoCs and FPGAs
05:13
Power Optimization in Battery Based Wireless Sensor Nodes
01:58
Using JTAG with the UCD3138: Setting up the xds10USB JTAG emulator
arrow-top
close
delete
download
menu
search
sortingArrows
zoom-in
zoom-out
arrow-down
arrow-up
arrowCircle-left
arrowCircle-right
blockDiagram
calculator
calendar
chatBubble-double
chatBubble-person
chatBubble-single
checkmark-circle
chevron-down
chevron-left
chevron-right
chevron-up
chip
clipboard
close-circle
crossReference
dash
document-generic
document-pdfAcrobat
document-web
evaluationModule
globe
historyClock
info-circle
list
lock
mail
myTI
onlineDataSheet
person
phone
question-circle
referenceDesign
shoppingCart
star
tools
videos
warning
wiki