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

Salient points about addressing mode, Salient points about addressing mode ...

Salient points about addressing mode are:  This addressing mode is employed to initialise value of a variable. Benefit of this mode is that no extra memory accesses are

Explain the generic framework for electronic commerce, Explain the generic ...

Explain the generic framework for electronic commerce along with suitable diagram? Generic Framework for electronic commerce comprises the Applications of EC (as like banking,

Illustrate left shift register with parallel load, Q. Illustrate Left shift...

Q. Illustrate Left shift register with parallel load? A register that shifts data in one direction only is known as Uni-directional shift register and a register that can shift

Big – endian and little- endian representations, Explain Big - Endian and L...

Explain Big - Endian and Little- Endian representations Ans: The Big- endian is used where lower byte addresses are used for the more significant bytes (leftmost bytes) of the

Ms access database through menu driven selections, Would you like to easily...

Would you like to easily automate your MS Access database through menu driven selections? This can be accomplished by producing a form with customized buttons that point to macr

What is enhanced ide, Q. What is Enhanced IDE? The principle behind EID...

Q. What is Enhanced IDE? The principle behind EIDE interface is the same as in IDE interface however this drive has capacities varying from 10.2GB to 20.5GB. The rotation speed

Define immediate addressing mode with example, Q. Define Immediate Addressi...

Q. Define Immediate Addressing Mode with example? Immediate Addressing Mode An immediate operand can be a constant expression like a character, a number or an arithmetic e

Temporary registers w and z, Why the temporary registers W and Z are named ...

Why the temporary registers W and Z are named so I mean we start from A,B,C,D,E then H and L coz H stands for higher bit nd L for lower bit of the address pointed by memory pointer

What is a development class, What is a Development class? Related obje...

What is a Development class? Related objects from the ABAP/4 repository are assigned to the similar development class.  This enables you to right and transport related objects

Explain resource dependence, Resource Dependence The parallelism betwee...

Resource Dependence The parallelism between instructions can also be affected because of the shared resources. If two instructions are occupying the same shared resource then i

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