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

two arguments are passed, The velocity of sound in air is 49.02 feet p...

The velocity of sound in air is 49.02 feet per second where is the air temperature in degrees Rankine.  Write a function to execute this.  If just 1 argument is passed to the f

What is a customer-to-business transaction, What is a customer-to-business ...

What is a customer-to-business transaction? C2B (customer-to-business): The most significant activity into e-commerce isn’t selling. That is buying. Rather often which do

Super ascii string cost, ascii code add=2unit,replace=1unit,delete=3unit.co...

ascii code add=2unit,replace=1unit,delete=3unit.convert ascii code in minimum cost

What is a subroutine, What is a subroutine? A subroutine is a named, in...

What is a subroutine? A subroutine is a named, independent section of C code that performs a particular task and optionally returns a value to the calling program.

Explain about programmable logic array, Q. Explain about Programmable Logic...

Q. Explain about Programmable Logic Array? Until now individual gates are considered as fundamental building blocks from that different logic functions can be derived. With the

Use string manipulating functions , Write a script that will first initiali...

Write a script that will first initialize a string variable that will kept x and y coordinates of a point in the form 'x 3.1 y 6.4'.  Then, use string manipulating functions to ext

Move the layout table, You can select and move a layout table to other area...

You can select and move a layout table to other areas in a particular document. You can't, though, move a layout table so that it overlaps another. Next you will move the table

Explain what are the different hazards, There are situations, called hazard...

There are situations, called hazards that stop the next instruction in the instruction stream from implementing during its designated clock cycle. Hazards decrease the performance

By which the information is stored in ROM, The information in ROM is stored...

The information in ROM is stored ? Ans. By the manufacturer throughout fabrication of the device.

Benefits of device controllers, Q. Benefits of Device controllers? Usin...

Q. Benefits of Device controllers? Using device controllers for attaching I/O devices to a computer system in place of connecting them directly to system bus has subsequent ben

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