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

Message passing model, In the message-passing model, there exists a set of ...

In the message-passing model, there exists a set of tasks that use their own local memories during computation. Multiple tasks can reside on the similar physical machine as well ac

Explain the daa instruction, Explain the DAA DAA instruction follows th...

Explain the DAA DAA instruction follows the ADC or ADD instruction to adjust the result into a BCD result. DAA instruction functions only with the AL register, this addition sh

Why a function should have at least one input, Why a function should have a...

Why a function should have at least one input? There is no strong reason for this in verilog. I think this restriction isn't removed fin SystemVerilog. Some requirements where

What is central processing unit, What is Central Processing Unit Centra...

What is Central Processing Unit Central Processing Unit (CPU) performs all the arithmetic and logical calculations in a computer. The CPU is said to be the brain of the compute

Find minimum sampling rate of analog signal to be sampled, The analog signa...

The analog signal needs to be sampled at a minimum sampling rate of: (A) 2fs                                               (B) 1/(2fs) (C)  fs/2

Problem context and specification, Problem Context and Specification : ...

Problem Context and Specification : However the development of Inductive Logic Programming has been heavily formal in mathematical in nature it means the major people in the f

Cache-only memory access model (coma), Cache-Only Memory Access Model (COMA...

Cache-Only Memory Access Model (COMA) As we have discussed previous, shared memory multiprocessor systems may use cache memories with each processor for deducting the execution

Computer Graphics, Distinguish between uniform scaling differential scaling...

Distinguish between uniform scaling differential scaling

Explain three-way handshake mechanism, Explain Three-Way Handshake Mechanis...

Explain Three-Way Handshake Mechanism used by TCP to terminate a Session reliably. Just to guarantee that connection is sets up or terminated reliably, transfer control protoco

Explain pure and impure interpreters, Explain Pure and impure interpreters ...

Explain Pure and impure interpreters In a pure interpreter, the source program is retained into the source form all throughout its interpretation. These arrangements incur subs

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