SlideShare a Scribd company logo
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

More Related Content

What's hot

Introduction to Embedded Architecture
Introduction to Embedded Architecture Introduction to Embedded Architecture
Introduction to Embedded Architecture
amrutachintawar239
 
Communication protocols - Embedded Systems
Communication protocols - Embedded SystemsCommunication protocols - Embedded Systems
Communication protocols - Embedded Systems
Emertxe Information Technologies Pvt Ltd
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
Mohamed Abdallah
 
Memory mapped I/O and Isolated I/O
Memory mapped I/O and Isolated I/OMemory mapped I/O and Isolated I/O
Memory mapped I/O and Isolated I/O
Bharat Kharbanda
 
Addressing sequencing
Addressing sequencingAddressing sequencing
Addressing sequencing
rajshreemuthiah
 
Embedded system design challenges
Embedded system design challenges Embedded system design challenges
Embedded system design challenges
Aditya Kamble
 
Embedded C - Lecture 4
Embedded C - Lecture 4Embedded C - Lecture 4
Embedded C - Lecture 4
Mohamed Abdallah
 
Arm instruction set
Arm instruction setArm instruction set
Arm instruction set
Mathivanan Natarajan
 
8051 memory
8051 memory8051 memory
8051 memory
Mayank Garg
 
ARM Architecture
ARM ArchitectureARM Architecture
ARM Architecture
Dwight Sabio
 
Introduction to intel galileo board gen2
Introduction to intel galileo board gen2Introduction to intel galileo board gen2
Introduction to intel galileo board gen2
Harshit Srivastava
 
Direct memory access (dma)
Direct memory access (dma)Direct memory access (dma)
Direct memory access (dma)
Zubair Khalid
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051
SARITHA REDDY
 
Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086
Urvashi Singh
 
Design of embedded systems
Design of embedded systemsDesign of embedded systems
Design of embedded systemsPradeep Kumar TS
 
Misra c rules
Misra c rulesMisra c rules
Misra c rules
kiranyeligati
 
ARM CORTEX M3 PPT
ARM CORTEX M3 PPTARM CORTEX M3 PPT
ARM CORTEX M3 PPT
Gaurav Verma
 
Embedded C - Day 1
Embedded C - Day 1Embedded C - Day 1
Chapter 1-Microprocessors, Microcomputers, and Assembly Language
Chapter 1-Microprocessors, Microcomputers, and Assembly LanguageChapter 1-Microprocessors, Microcomputers, and Assembly Language
Chapter 1-Microprocessors, Microcomputers, and Assembly Language
cmkandemir
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Ganesh Ram
 

What's hot (20)

Introduction to Embedded Architecture
Introduction to Embedded Architecture Introduction to Embedded Architecture
Introduction to Embedded Architecture
 
Communication protocols - Embedded Systems
Communication protocols - Embedded SystemsCommunication protocols - Embedded Systems
Communication protocols - Embedded Systems
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
 
Memory mapped I/O and Isolated I/O
Memory mapped I/O and Isolated I/OMemory mapped I/O and Isolated I/O
Memory mapped I/O and Isolated I/O
 
Addressing sequencing
Addressing sequencingAddressing sequencing
Addressing sequencing
 
Embedded system design challenges
Embedded system design challenges Embedded system design challenges
Embedded system design challenges
 
Embedded C - Lecture 4
Embedded C - Lecture 4Embedded C - Lecture 4
Embedded C - Lecture 4
 
Arm instruction set
Arm instruction setArm instruction set
Arm instruction set
 
8051 memory
8051 memory8051 memory
8051 memory
 
ARM Architecture
ARM ArchitectureARM Architecture
ARM Architecture
 
Introduction to intel galileo board gen2
Introduction to intel galileo board gen2Introduction to intel galileo board gen2
Introduction to intel galileo board gen2
 
Direct memory access (dma)
Direct memory access (dma)Direct memory access (dma)
Direct memory access (dma)
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051
 
Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086
 
Design of embedded systems
Design of embedded systemsDesign of embedded systems
Design of embedded systems
 
Misra c rules
Misra c rulesMisra c rules
Misra c rules
 
ARM CORTEX M3 PPT
ARM CORTEX M3 PPTARM CORTEX M3 PPT
ARM CORTEX M3 PPT
 
Embedded C - Day 1
Embedded C - Day 1Embedded C - Day 1
Embedded C - Day 1
 
Chapter 1-Microprocessors, Microcomputers, and Assembly Language
Chapter 1-Microprocessors, Microcomputers, and Assembly LanguageChapter 1-Microprocessors, Microcomputers, and Assembly Language
Chapter 1-Microprocessors, Microcomputers, and Assembly Language
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))
 

Viewers also liked

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 Inheritance
adil raja
 
I2C programming with C and Arduino
I2C programming with C and ArduinoI2C programming with C and Arduino
I2C programming with C and Arduino
sato262
 
Protols used in bluetooth
Protols used in bluetoothProtols used in bluetooth
Protols used in bluetooth
Sonali Parab
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
Ronak Chhajed
 
Arm processor
Arm processorArm processor
Arm processor
SHREEHARI WADAWADAGI
 
Embedded C
Embedded CEmbedded C
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
Anurag Tomar
 
Arm developement
Arm developementArm developement
Arm developement
hirokiht
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
Abhijeet kapse
 
SPI Protocol
SPI ProtocolSPI Protocol
SPI Protocol
Anurag Tomar
 
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
 
Introduction to Embedded System
Introduction to Embedded SystemIntroduction to Embedded System
Introduction to Embedded System
Emertxe Information Technologies Pvt Ltd
 
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 interface
Abhijeet 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
 
Iot
IotIot

Viewers also liked (18)

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
 
Embedded C
Embedded CEmbedded C
Embedded C
 
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
 

Similar to Embedded C - Optimization techniques

Mod.2.pptx
Mod.2.pptxMod.2.pptx
Mod.2.pptx
Kokilak27
 
Programming concepts By ZAK
Programming concepts By ZAKProgramming concepts By ZAK
Programming concepts By ZAK
Tabsheer Hasan
 
Low memory footprint programs-iSeries
Low memory footprint programs-iSeriesLow memory footprint programs-iSeries
Low memory footprint programs-iSeries
Prithiviraj Damodaran
 
代码大全(内训)
代码大全(内训)代码大全(内训)
代码大全(内训)
Horky Chen
 
Modularisation techniques new
Modularisation techniques newModularisation techniques new
Modularisation techniques new
Jeet Thombare
 
sCode optimization
sCode optimizationsCode optimization
sCode optimization
Satyamevjayte Haxor
 
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
Alithya
 
Software for embedded systems complete
Software for embedded systems completeSoftware for embedded systems complete
Software for embedded systems complete
Anand Kumar
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
Karthik Vivek
 
C question
C questionC question
C question
Kuntal Bhowmick
 
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
PVS-Studio
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
Karthik Vivek
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
Karthik Vivek
 
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
Dr. 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 Tagare
Apache 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 flattening
CAFxX
 
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
Brian 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 Researches
theijes
 

Similar to 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
 

More from Emertxe Information Technologies Pvt Ltd

Career Transition (1).pdf
Career Transition (1).pdfCareer Transition (1).pdf
Career Transition (1).pdf
Emertxe Information Technologies Pvt Ltd
 
10_isxdigit.pdf
10_isxdigit.pdf10_isxdigit.pdf

More from 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
 

Recently uploaded

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 

Recently uploaded (20)

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 

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)");