SlideShare une entreprise Scribd logo
1  sur  37
Télécharger pour lire hors ligne
C Optimization
Techniques
Team Emertxe
Optimization ?
✔ Program optimization or software optimization is
the process of modifying a software system to make
some aspect of it work more efficiently or use fewer
resources.
✔ Optimization is a process of improving efficiency of
a program in time (speed) or Space (size).
Categories of
Optimization ?
✔ Space Optimization Time Optimization
General
Phenomenon
Note : However this may not always true.
Code size speed
Bigger Greater
Smaller Lesser
Compiler
Code Optimization
✔ Compilers can be designed to provide code
optimization.
✔ Users should only focus on optimization not
provided by the compiler such as choosing a faster
and/or less memory intensive algorithm
Optimization:
Methods
✔ Choice of Compiler
✔ Compiler settings
✔ Programming Algorithm and Techniques
✔ Rewriting program in Assembly
✔ Code profilers
✔ Disassemble & code analysis
Programming
Algorithms & Techniques
✔ Data Handling
✔ Flow control
✔ Other Handling
Data Handling
✔ RAM Usage
✔ Data Types Usage
✔ Avoid Type Coversion
✔ Unsigned Advantage
✔ Float & Double
✔ Constant & Volatile
✔ Data Alignment – Arrangement & Packing
✔ Pass by Reference
RAM Usage
✔ Four main Component of program memory
Text
Data
Heap
Stack
✔ The reduction in one component will enable the increase in the
others.
✔ Unlike stack and heap, which are dynamic in nature, global data is
fixed in size.
Data Usage Types
The use of correct data type is important in a recursive calculation or
large array processing.
The extra size, which is not required, is taking up much space and
processing time.
Example:
If your variable range is varying in between 0 to 200 then you should take variable type
of unsigned char.
Avoid
Type Conversion
✔ Programmers should plan to use the same type of variables for
processing. Type conversion must be avoided.
✔ Otherwise, precious cycles will be waste to convert one type to
another (here Signed and Unsigned variables are considered as
different types.)
Usage: Signed &
Unsigned
In summary,
✔ use unsigned types for:
Division and remainders
Loop counters
Array indexing
✔ Use signed types for:
Integer-to-floating-point conversion
Floats & Doubles
✔ Maximum value of Float = 0x7F7F FFFF
✔ Maximum Value of Double = 0x7F7F FFFF FFFF FFFF
✔ To avoid the unnecessary type conversion or confusion,
programmers can assign the letter 'f' following the numeric value.
x = y + 0.2f;
Const & Volatile
✔ The “const” keyword is to define the data as a constant, which will
allocate it in the ROM space.
✔ Otherwise a RAM space will also be reserved for this data. This is
unnecessary as the constant data is supposed to be read-only.
Data Alignment :
Arrangment and Packing
✔ The declaration of the component in a structure will determine how
the components are being stored.
✔ Due to the Memory alignment, it is possible to have dummy area
within the structure. It is advised to place all similar size variables
in the same group.
Data Arrangment
Structure Padding
✔ As the structure is packed, integer b will not be aligned. This will
improve the RAM size but operational speed will be degraded, as the
access of ‘b’ will take up two cycles.
Pass by Reference
✔ Larger numbers of parameters may be costly due to the number of
pushing and popping actions on each function call.
✔ It is more efficient to pass structure reference as parameters to
reduce this overhead.
Arrays & Structure:
Initialization
✔ Illustration
Return Value
✔ The return value of a function will be stored in a register. If this
return data has no intended usage, time and space are wasted in
storing this information.
✔ Programmer should define the function as “void” to minimize the
extra handling in the function.
Flow Control
✔ Use of switch statement
✔ Inline function
✔ Loop unrolling
✔ Loop Hoisting
✔ Loop Overhead
Switch & Non-Contiguous
Case Expressions
✔ Use if-else statements in place of switch statements that have
noncontiguous case expressions.
✔ If the case expressions are contiguous or nearly contiguous integer
values, most compilers translate the switch statement as a jump table
instead of a comparison chain.
Inline Function
✔ The technique will cause the compiler to replace all calls to the
function, with a copy of the function’s code.
✔ This will eliminate the runtime overhead associated with the function
call.
✔ This is most effective if the function is called frequently, but contains
only a few lines of code.
✔ In-lining large functions will make the executable too large.
Loop Unrolling
✔ Loop unrolling tries to get rid of the checks completely or to reduce
the number of checks.
✔ If you know a loop is only performed a certain number of times, or if
you know the number of times it will be repeated is a multiple of a
constant you can unroll this loop.
Loop Hoisting
✔ Moving computations outside loops
✔ Saves computing time
Loop Overhead
✔ The MCU have a conditional branch mechanism that works well when
counting down from positive number to zero.
✔ It is easier to detect “Zero” (Branch non zero – single instruction) than
a “predefined number” (Compare and perform jump – two
instructions)
Other Handling
✔ Use of operators
✔ Use formula
✔ Inline Assembly
✔ Fixed point & Floating point
Use of operators
Replacing: Integer
Division With Multiplication
✔ Replace integer division with multiplication when there are multiple
divisions in an expression.
✔ This is possible only if no overflow will occur during the
computation of the product. The possibility of an overflow can be
determined by considering the possible ranges of the divisors.
✔ Integer division is the slowest of all integer arithmetic operations.
Example
Use finite differences to
Avoid multiplies
Module by &
Extracting common
subexpressions
✔ Manually extract common subexpressions where C compilers may be
unable to extract them from floating-point expressions due to the
guarantee against reordering of such expressions in the ANSI
standard.
Manual Optimization
Example 1
Manual Optimization
Example 2
Use Formula
✔ Use formula instead of loops
✔ What is the formula for sum of naturals numbers?
Example
Use Formula
Example
Example
Inline Assembly
In case you want write code is best optimized assembly code,
__asm__ ("movl %eax, %ebxnt"
"movl $56, %esint"
"movl %ecx, $label(%edx,%ebx,$4)nt"
"movb %ah, (%ebx)");
THANK YOU

Contenu connexe

Tendances (20)

Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 
Arm architecture chapter2_steve_furber
Arm architecture chapter2_steve_furberArm architecture chapter2_steve_furber
Arm architecture chapter2_steve_furber
 
Embedded C - Day 1
Embedded C - Day 1Embedded C - Day 1
Embedded C - Day 1
 
Embedded _c_
Embedded  _c_Embedded  _c_
Embedded _c_
 
ARM Exception and interrupts
ARM Exception and interrupts ARM Exception and interrupts
ARM Exception and interrupts
 
Hardware Software Codesign
Hardware Software CodesignHardware Software Codesign
Hardware Software Codesign
 
LECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORSLECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORS
 
NUMA overview
NUMA overviewNUMA overview
NUMA overview
 
Parallel processing
Parallel processingParallel processing
Parallel processing
 
Multi core-architecture
Multi core-architectureMulti core-architecture
Multi core-architecture
 
Serial Communication Interfaces
Serial Communication InterfacesSerial Communication Interfaces
Serial Communication Interfaces
 
Module 2 ARM CORTEX M3 Instruction Set and Programming
Module 2 ARM CORTEX M3 Instruction Set and ProgrammingModule 2 ARM CORTEX M3 Instruction Set and Programming
Module 2 ARM CORTEX M3 Instruction Set and Programming
 
RTOS Basic Concepts
RTOS Basic ConceptsRTOS Basic Concepts
RTOS Basic Concepts
 
Rtos concepts
Rtos conceptsRtos concepts
Rtos concepts
 
Embedded C
Embedded CEmbedded C
Embedded C
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating System
 
Processor Organization and Architecture
Processor Organization and ArchitectureProcessor Organization and Architecture
Processor Organization and Architecture
 
Embedded systems notes
Embedded systems notesEmbedded systems notes
Embedded systems notes
 
Interfacing memory with 8086 microprocessor
Interfacing memory with 8086 microprocessorInterfacing memory with 8086 microprocessor
Interfacing memory with 8086 microprocessor
 
Introduction to embedded system design
Introduction to embedded system designIntroduction to embedded system design
Introduction to embedded system design
 

En vedette

Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Janki Shah
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritanceadil raja
 
I2C programming with C and Arduino
I2C programming with C and ArduinoI2C programming with C and Arduino
I2C programming with C and Arduinosato262
 
Protols used in bluetooth
Protols used in bluetoothProtols used in bluetooth
Protols used in bluetoothSonali Parab
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral InterfaceAnurag Tomar
 
Arm developement
Arm developementArm developement
Arm developementhirokiht
 
Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)Adair Dingle
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)Varun Mahajan
 
Serial peripheral interface
Serial peripheral interfaceSerial peripheral interface
Serial peripheral interfaceAbhijeet kapse
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Dhaval Kaneria
 
Code Optimization
Code OptimizationCode Optimization
Code Optimizationguest9f8315
 

En vedette (17)

Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
I2C programming with C and Arduino
I2C programming with C and ArduinoI2C programming with C and Arduino
I2C programming with C and Arduino
 
Protols used in bluetooth
Protols used in bluetoothProtols used in bluetooth
Protols used in bluetooth
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Arm processor
Arm processorArm processor
Arm processor
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
 
Arm developement
Arm developementArm developement
Arm developement
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 
SPI Protocol
SPI ProtocolSPI Protocol
SPI Protocol
 
Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)
 
Introduction to Embedded System
Introduction to Embedded SystemIntroduction to Embedded System
Introduction to Embedded System
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)
 
Serial peripheral interface
Serial peripheral interfaceSerial peripheral interface
Serial peripheral interface
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Iot
IotIot
Iot
 

Similaire à Embedded C - Optimization techniques

Programming concepts By ZAK
Programming concepts By ZAKProgramming concepts By ZAK
Programming concepts By ZAKTabsheer Hasan
 
Low memory footprint programs-iSeries
Low memory footprint programs-iSeriesLow memory footprint programs-iSeries
Low memory footprint programs-iSeriesPrithiviraj Damodaran
 
代码大全(内训)
代码大全(内训)代码大全(内训)
代码大全(内训)Horky Chen
 
Modularisation techniques new
Modularisation techniques newModularisation techniques new
Modularisation techniques newJeet Thombare
 
Getting Started with Calc Manager for HFM
Getting Started with Calc Manager for HFMGetting Started with Calc Manager for HFM
Getting Started with Calc Manager for HFMAlithya
 
Software for embedded systems complete
Software for embedded systems completeSoftware for embedded systems complete
Software for embedded systems completeAnand Kumar
 
Lesson 26. Optimization of 64-bit programs
Lesson 26. Optimization of 64-bit programsLesson 26. Optimization of 64-bit programs
Lesson 26. Optimization of 64-bit programsPVS-Studio
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review ProcessDr. Syed Hassan Amin
 
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra TagareActionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra TagareApache Apex
 
Compiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flatteningCompiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flatteningCAFxX
 
So You Want to Write an Exporter
So You Want to Write an ExporterSo You Want to Write an Exporter
So You Want to Write an ExporterBrian Brazil
 
FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)Yogesh Deshpande
 
Effective cplusplus
Effective cplusplusEffective cplusplus
Effective cplusplusMark Veltzer
 
Practical Guides on Programming with Big Number Library in Scientific Researches
Practical Guides on Programming with Big Number Library in Scientific ResearchesPractical Guides on Programming with Big Number Library in Scientific Researches
Practical Guides on Programming with Big Number Library in Scientific Researchestheijes
 

Similaire à Embedded C - Optimization techniques (20)

Mod.2.pptx
Mod.2.pptxMod.2.pptx
Mod.2.pptx
 
Programming concepts By ZAK
Programming concepts By ZAKProgramming concepts By ZAK
Programming concepts By ZAK
 
Low memory footprint programs-iSeries
Low memory footprint programs-iSeriesLow memory footprint programs-iSeries
Low memory footprint programs-iSeries
 
代码大全(内训)
代码大全(内训)代码大全(内训)
代码大全(内训)
 
Modularisation techniques new
Modularisation techniques newModularisation techniques new
Modularisation techniques new
 
sCode optimization
sCode optimizationsCode optimization
sCode optimization
 
Getting Started with Calc Manager for HFM
Getting Started with Calc Manager for HFMGetting Started with Calc Manager for HFM
Getting Started with Calc Manager for HFM
 
Software for embedded systems complete
Software for embedded systems completeSoftware for embedded systems complete
Software for embedded systems complete
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
 
C question
C questionC question
C question
 
Lesson 26. Optimization of 64-bit programs
Lesson 26. Optimization of 64-bit programsLesson 26. Optimization of 64-bit programs
Lesson 26. Optimization of 64-bit programs
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
 
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra TagareActionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
 
Compiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flatteningCompiler optimizations based on call-graph flattening
Compiler optimizations based on call-graph flattening
 
So You Want to Write an Exporter
So You Want to Write an ExporterSo You Want to Write an Exporter
So You Want to Write an Exporter
 
FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)
 
Effective cplusplus
Effective cplusplusEffective cplusplus
Effective cplusplus
 
Practical Guides on Programming with Big Number Library in Scientific Researches
Practical Guides on Programming with Big Number Library in Scientific ResearchesPractical Guides on Programming with Big Number Library in Scientific Researches
Practical Guides on Programming with Big Number Library in Scientific Researches
 

Plus de Emertxe Information Technologies Pvt Ltd

Plus de Emertxe Information Technologies Pvt Ltd (20)

premium post (1).pdf
premium post (1).pdfpremium post (1).pdf
premium post (1).pdf
 
Career Transition (1).pdf
Career Transition (1).pdfCareer Transition (1).pdf
Career Transition (1).pdf
 
10_isxdigit.pdf
10_isxdigit.pdf10_isxdigit.pdf
10_isxdigit.pdf
 
01_student_record.pdf
01_student_record.pdf01_student_record.pdf
01_student_record.pdf
 
02_swap.pdf
02_swap.pdf02_swap.pdf
02_swap.pdf
 
01_sizeof.pdf
01_sizeof.pdf01_sizeof.pdf
01_sizeof.pdf
 
07_product_matrix.pdf
07_product_matrix.pdf07_product_matrix.pdf
07_product_matrix.pdf
 
06_sort_names.pdf
06_sort_names.pdf06_sort_names.pdf
06_sort_names.pdf
 
05_fragments.pdf
05_fragments.pdf05_fragments.pdf
05_fragments.pdf
 
04_magic_square.pdf
04_magic_square.pdf04_magic_square.pdf
04_magic_square.pdf
 
03_endianess.pdf
03_endianess.pdf03_endianess.pdf
03_endianess.pdf
 
02_variance.pdf
02_variance.pdf02_variance.pdf
02_variance.pdf
 
01_memory_manager.pdf
01_memory_manager.pdf01_memory_manager.pdf
01_memory_manager.pdf
 
09_nrps.pdf
09_nrps.pdf09_nrps.pdf
09_nrps.pdf
 
11_pangram.pdf
11_pangram.pdf11_pangram.pdf
11_pangram.pdf
 
10_combinations.pdf
10_combinations.pdf10_combinations.pdf
10_combinations.pdf
 
08_squeeze.pdf
08_squeeze.pdf08_squeeze.pdf
08_squeeze.pdf
 
07_strtok.pdf
07_strtok.pdf07_strtok.pdf
07_strtok.pdf
 
06_reverserec.pdf
06_reverserec.pdf06_reverserec.pdf
06_reverserec.pdf
 
05_reverseiter.pdf
05_reverseiter.pdf05_reverseiter.pdf
05_reverseiter.pdf
 

Dernier

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Dernier (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Embedded C - Optimization techniques

  • 2. Optimization ? ✔ Program optimization or software optimization is the process of modifying a software system to make some aspect of it work more efficiently or use fewer resources. ✔ Optimization is a process of improving efficiency of a program in time (speed) or Space (size).
  • 3. Categories of Optimization ? ✔ Space Optimization Time Optimization
  • 4. General Phenomenon Note : However this may not always true. Code size speed Bigger Greater Smaller Lesser
  • 5. Compiler Code Optimization ✔ Compilers can be designed to provide code optimization. ✔ Users should only focus on optimization not provided by the compiler such as choosing a faster and/or less memory intensive algorithm
  • 6. Optimization: Methods ✔ Choice of Compiler ✔ Compiler settings ✔ Programming Algorithm and Techniques ✔ Rewriting program in Assembly ✔ Code profilers ✔ Disassemble & code analysis
  • 7. Programming Algorithms & Techniques ✔ Data Handling ✔ Flow control ✔ Other Handling
  • 8. Data Handling ✔ RAM Usage ✔ Data Types Usage ✔ Avoid Type Coversion ✔ Unsigned Advantage ✔ Float & Double ✔ Constant & Volatile ✔ Data Alignment – Arrangement & Packing ✔ Pass by Reference
  • 9. RAM Usage ✔ Four main Component of program memory Text Data Heap Stack ✔ The reduction in one component will enable the increase in the others. ✔ Unlike stack and heap, which are dynamic in nature, global data is fixed in size.
  • 10. Data Usage Types The use of correct data type is important in a recursive calculation or large array processing. The extra size, which is not required, is taking up much space and processing time. Example: If your variable range is varying in between 0 to 200 then you should take variable type of unsigned char.
  • 11. Avoid Type Conversion ✔ Programmers should plan to use the same type of variables for processing. Type conversion must be avoided. ✔ Otherwise, precious cycles will be waste to convert one type to another (here Signed and Unsigned variables are considered as different types.)
  • 12. Usage: Signed & Unsigned In summary, ✔ use unsigned types for: Division and remainders Loop counters Array indexing ✔ Use signed types for: Integer-to-floating-point conversion
  • 13. Floats & Doubles ✔ Maximum value of Float = 0x7F7F FFFF ✔ Maximum Value of Double = 0x7F7F FFFF FFFF FFFF ✔ To avoid the unnecessary type conversion or confusion, programmers can assign the letter 'f' following the numeric value. x = y + 0.2f;
  • 14. Const & Volatile ✔ The “const” keyword is to define the data as a constant, which will allocate it in the ROM space. ✔ Otherwise a RAM space will also be reserved for this data. This is unnecessary as the constant data is supposed to be read-only.
  • 15. Data Alignment : Arrangment and Packing ✔ The declaration of the component in a structure will determine how the components are being stored. ✔ Due to the Memory alignment, it is possible to have dummy area within the structure. It is advised to place all similar size variables in the same group.
  • 17. Structure Padding ✔ As the structure is packed, integer b will not be aligned. This will improve the RAM size but operational speed will be degraded, as the access of ‘b’ will take up two cycles.
  • 18. Pass by Reference ✔ Larger numbers of parameters may be costly due to the number of pushing and popping actions on each function call. ✔ It is more efficient to pass structure reference as parameters to reduce this overhead.
  • 20. Return Value ✔ The return value of a function will be stored in a register. If this return data has no intended usage, time and space are wasted in storing this information. ✔ Programmer should define the function as “void” to minimize the extra handling in the function.
  • 21. Flow Control ✔ Use of switch statement ✔ Inline function ✔ Loop unrolling ✔ Loop Hoisting ✔ Loop Overhead
  • 22. Switch & Non-Contiguous Case Expressions ✔ Use if-else statements in place of switch statements that have noncontiguous case expressions. ✔ If the case expressions are contiguous or nearly contiguous integer values, most compilers translate the switch statement as a jump table instead of a comparison chain.
  • 23. Inline Function ✔ The technique will cause the compiler to replace all calls to the function, with a copy of the function’s code. ✔ This will eliminate the runtime overhead associated with the function call. ✔ This is most effective if the function is called frequently, but contains only a few lines of code. ✔ In-lining large functions will make the executable too large.
  • 24. Loop Unrolling ✔ Loop unrolling tries to get rid of the checks completely or to reduce the number of checks. ✔ If you know a loop is only performed a certain number of times, or if you know the number of times it will be repeated is a multiple of a constant you can unroll this loop.
  • 25. Loop Hoisting ✔ Moving computations outside loops ✔ Saves computing time
  • 26. Loop Overhead ✔ The MCU have a conditional branch mechanism that works well when counting down from positive number to zero. ✔ It is easier to detect “Zero” (Branch non zero – single instruction) than a “predefined number” (Compare and perform jump – two instructions)
  • 27. Other Handling ✔ Use of operators ✔ Use formula ✔ Inline Assembly ✔ Fixed point & Floating point
  • 29. Replacing: Integer Division With Multiplication ✔ Replace integer division with multiplication when there are multiple divisions in an expression. ✔ This is possible only if no overflow will occur during the computation of the product. The possibility of an overflow can be determined by considering the possible ranges of the divisors. ✔ Integer division is the slowest of all integer arithmetic operations. Example
  • 30. Use finite differences to Avoid multiplies Module by &
  • 31. Extracting common subexpressions ✔ Manually extract common subexpressions where C compilers may be unable to extract them from floating-point expressions due to the guarantee against reordering of such expressions in the ANSI standard.
  • 34. Use Formula ✔ Use formula instead of loops ✔ What is the formula for sum of naturals numbers? Example
  • 36. Inline Assembly In case you want write code is best optimized assembly code, __asm__ ("movl %eax, %ebxnt" "movl $56, %esint" "movl %ecx, $label(%edx,%ebx,$4)nt" "movb %ah, (%ebx)");