Code Optimisation and CDFG

Status
Not open for further replies.

soc

Junior Member level 3
Joined
Oct 9, 2006
Messages
25
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,464
Hello,
I want to know the correct answer for the following problems,since these were part of exam and just want to know if I did right and if wrong ,then like to know the correct solution.

Thanks


1.what will be the CDFG and the longest and shortest path for the given code,assuming each execution takes one time unit

n = 5;
if (a < b)
n = 4;
for (i = 0; i < n; i++) {
if (c > 0)
x++;
else {
x--;
y++;
}
}

2.Code optimisation
a) only optimisations are allowed that do not increase the code size
b)all optimisations are allowed.

int a[10], b[10], c[10];
// ...
int f() {
int i;
for(i = 1; i < 10; i++)
a = b + c;
}
int g(int n) {
int y = 0;
int i;
for(i = 1; i < 2*n; i++)
y += c;
return y;
}
int main() {
// ...
f();
y = g(5);
// ...
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…