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

What is public key cryptography, What is Public Key Cryptography Publi...

What is Public Key Cryptography Public-key cryptography is a form of modern cryptography which permits users to communicate safely without lastly agreeing on a shared secret

And-elimination rule, And-Elimination rule: In generally English says ...

And-Elimination rule: In generally English says that "if you know that lots of things are all true, so you know like any one of them is also true". Because you can specify a c

Can a .net web application consume java web service, Can a .NET web applica...

Can a .NET web application consume Java web service? Yes Offcourse.Actually Webservices are independent  to language. It depends on WSDL and SOAP. so any single can develope t

What is .net and .net framework, What is .NET / .NET Framework?  It is ...

What is .NET / .NET Framework?  It is a Framework in which Windows applications might be developed and run. The Microsoft .NET Framework is a platform for building, deploying,

Explain the disadvantages off-the-shelf, Explain the disadvantages Off-the...

Explain the disadvantages Off-the-shelf -  can be over-complex since it tries to cover as many characteristics as possible (for example most users of Word only utilise about

Define multiprogramming, Define Multiprogramming. Multiprogramming: ...

Define Multiprogramming. Multiprogramming: A multiprogramming operating system is system which allows extra than one active user program or part of user program to be store

Why echo suppressor is detrimental to full duplex operation, Echo suppresso...

Echo suppressor is detrimental to full duplex operation because? This disables one of the two pairs in a four-wire trunk line while a signal is detected upon another pair.

What are qualified associations, What are qualified associations? A qua...

What are qualified associations? A qualified association is an association in which an attribute known as the qualifier disambiguates the object many associated end.

Two ethernet switches sw1 and sw2 , Six machines H1, H2, ..., H6 are linked...

Six machines H1, H2, ..., H6 are linked by two Ethernet switches SW1 and SW2 as given below. Both switches have four ports drawn. The port numbers are as indicated. Suppose the two

Smallest and largest integer , A given microprocessor has words of 1 byte. ...

A given microprocessor has words of 1 byte.  What is the smallest and largest integer that can be characterized in the following representations?   a) unsigned b) sign- ma

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