Real Time Systems Design And Analysis

Chapter 7.6.13 - Dead-Variable Elimination

7.6.13   Dead-Variable Elimination

A variable is live at a point in a program if its value can be used subsequently;
otherwise it is dead and subject to removal. The following code illustrates that z
is a dead variable:

x=y+z;
x=y;


after removal of z, what is left is

x=y;

While this example appears to be trivial, again it could arise as the result of
poor coding or an automated code generation or translation process.


7.6.14   Short-Circuiting Boolean Code


The test of compound Boolean expressions can be optimized by testing each
subexpression separately. Consider the following:

if (x > 0 && y>0)
  z = 1;


which could be replaced by

if (x>0)
    if (y>0)
  z = 1;


In many compilers, the code generated by the second fragment will be superior
to the first. ANSI-C, however, executes if (expression) constructs sequentially
inside the () and drops out the first FALSE condition. That is, it will
automatically short-circuit Boolean code.


7.6.15   Loop Unrolling

Loop unrolling duplicates statements executed in a loop in order to reduce the
number of operations, and hence the loop overhead incurred. In the exaggerated
case, the loop is completely replaced by inline code. For example,

for(i=1;i<=6;i++)
    a[i] = a[i]*8;


is replaced by

a[1]=a[1]*8;
a[2]=a[2]*8;
a[3]=a[3]*8;
a[4]=a[4]*8;
a[5]=a[5]*8;
a[6]=a[6]*8;


A less dramatic version reduces the loop overhead by a factor of 3:

for (i=1;i<=6;i+3)

{

 a[i]=a[i]*8;
a[i+1]=a[i+1]*8;
a[i+2]=a[i+2]*8;

};

 

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: PCMCIA Memory Cards
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.