Explain the commonly used code optimization techniques, Computer Engineering

Assignment Help:

Explain briefly any three of the commonly used code optimization techniques.

1. Common sub expression elimination:

In given expression as "(a+b)-(a+b)/4", in such "common sub-expression" termed to the duplicated "(a+b)". Compilers implementing such technique realize that "(a+b)" would not modify, and by itself, only compute its value once and use similar value next time.

2. Dead code Elimination:

Code which is unreachable or which does not influence the program (for example dead stores) can be removed. In the illustration below, the value assigned to i is never utilized, and the dead store can be removed. The first assignment to global is dead, and the third assignment to global is not reachable; both can be removed.

int global; void f (){ int i;

i = 1;          /* dead store */

global = 1;     /* dead store */

global = 2;

return;

global = 3;     /* unreachable */}

Below is the code fragment after dead code elimination.

int global;

void f (){ global = 2; return;}

3. Loop-invariant code motion

If a quantity is calculated inside a loop during iteration and its value is similar for iteration, this can vastly improve efficiency to hoist this outside the loop and calculate its value just once before the loop begins. It is particularly significant with the address-calculation expressions generated through loops over arrays. For accurate implementation, such technique must be utilized with loop inversion, since not all code is safe to be hoisted outside the loop.

For illustration:

 for (i=1; i≤10, i++){

x=y*2-(1)

.

.

.

}

statement 1 can be hoisted outside the loop assuming value of x and y does not modify in the loop.


Related Discussions:- Explain the commonly used code optimization techniques

Nmknl''knl, Ask question bhjjnjnnjnjm#Minimum 100 words accepted#

Ask question bhjjnjnnjnjm#Minimum 100 words accepted#

Explain creating files for writing only in c, Creating Files for Writing On...

Creating Files for Writing Only Creating Files for Writing Only : To create a text file for writing only, pass "w" into fopen as the second argument. This example follows along

What is dvd and dvd-rom, DVD is a new technology very same to compact discs...

DVD is a new technology very same to compact discs. A DVD looks just like an ordinary compact disc, though a DVD can hold up to 25 times as much as a CD!! That's 18 gigabytes!! Thi

What is functional modelling, What is  Functional Modelling  We know ...

What is  Functional Modelling  We know that Data flow modelling is an ordinary technique used for analysis of a problem in software engineering. It is very useful for analyzi

Total number of registers in a cpu, Q. Total number of registers in a CPU? ...

Q. Total number of registers in a CPU? Factors to consider when choosing total number of registers in a CPU are:  CPU can access registers faster than it can access m

Digital electronics, Draw a circuit of an NMOS inverter and explain its ope...

Draw a circuit of an NMOS inverter and explain its operation

Multi-threaded concurrency programming with threads, Your task is to implem...

Your task is to implement a memory manager that manages page reads and writes from multiple client threads. In the first programming task the memory manager keeps all the pages in

Colour management, There are three primary colours in pigments - Red, Yello...

There are three primary colours in pigments - Red, Yellow and Blue. There are two ways to produce more colours:   Physical Mixing: Physically mix colours to produce a new colour

Digital communication systems, a pcm has the following parameters a maximum...

a pcm has the following parameters a maximum analog input frequency of 4khz maximum decoded voltage at the receiver of 2.55v minimum dr of 6db compute minimum sampling rate,minimum

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd