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

How many types memory mgt can divided, They are of two types. They are big ...

They are of two types. They are big endian and little endian. Memory is separated into two bank, 1:even bank 2:odd bank.

What are the advantagesof fact finding, What are the Advantagesof fact find...

What are the Advantagesof fact finding - Analyst obtains reliable data - It's possible to see exactly what is being done -  This is an inexpensive method in comparison o

Draw a diagram to illustrate the design pattern, Problem: (a) What show...

Problem: (a) What shows a Pattern a Pattern? (b) Which pattern is given below? Justify your answer. public class A { private static A instance = null; private A() {

Source and destination are named the same, What happens if the both source ...

What happens if the both source and destination are named the same? Ans) The import operation present in MS Access does not overwrite or change any of the existing tables or obj

Explain the term thread scheduling, Problem: a) Most RMI and RPC system...

Problem: a) Most RMI and RPC systems expect to be supported by the "Request-Reply Protocol". Describe what "Request-Reply Protocol" is. b) Describe the invocation semantics

Explain rational robots coding standards, The standards are for all testers...

The standards are for all testers using the IDE of Rational Robot to make their automated test scripts. The mission is to decrease maintenance costs when it comes to changes.

Branch (control) hazards in computer architecture, Branch (control) hazards...

Branch (control) hazards in computer architecture : Branching hazards (also called control hazards) take place when the processor is told to branch -for example, if a defin

What is cable modem, Q What is Cable Modem? One more way of accessing I...

Q What is Cable Modem? One more way of accessing Internet currently being developed is use of cable modems. These require that you subscribe to a cable service as well as allow

Explain the random scan and raster scan displays, Define Random scan/Raste...

Define Random scan/Raster scan displays?  Random scan is a method in which the display is made by the electronic beam which is directed only to the points or part of the screen

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