loop optimization

Usage of VEX tools

loop optimization

Postby nik » Tue Feb 21, 2006 7:01 pm

hi,

I have a doubt on this piece of code from the function gfInvert of the pegwit algorithm that is executed the most of the time. There are two infinite loop that call each other. Through some printf we discovered that these loops call each other eight times and then the first one return.

How can I use #pragma rules in this case?

for (;;) {
if (f[0] == 1) {
assert (f[1] != 0);
gfSmallDiv (b, f[1]);
/* destroy potentially sensitive data: */
gfClear (c); gfClear (f); gfClear (g); x = j = alpha = 0;
return 0;
}
if (f[0] < g[0]) {
goto SWAP_FG;
}
SWAP_GF:
j = f[0] - g[0];
x = logt[f[f[0]]] - logt[g[g[0]]] + TOGGLE;
alpha = expt[x >= TOGGLE ? x - TOGGLE : x];
gfAddMul (f, alpha, j, g);
gfAddMul (b, alpha, j, c);
}

/* basically same code with b,c,f,g swapped */
for (;;) {
if (g[0] == 1) {
assert (g[1] != 0);
gfSmallDiv (c, g[1]);
gfCopy (b, c);
/* destroy potentially sensitive data: */
gfClear (c); gfClear (f); gfClear (g); x = j = alpha = 0;
return 0;
}
if (g[0] < f[0]) {
goto SWAP_GF;
}
SWAP_FG:
j = g[0] - f[0];
x = logt[g[g[0]]] - logt[f[f[0]]] + TOGGLE;
alpha = expt[x >= TOGGLE ? x - TOGGLE : x];
gfAddMul (g, alpha, j, f);
gfAddMul (c, alpha, j, b);
}
} /* gfInvert


Thanks,
Nicola
nik
 
Posts: 2
Joined: Mon Feb 20, 2006 7:04 pm

Re: loop optimization

Postby frb » Thu Feb 23, 2006 5:15 pm

nik wrote:hi,

I have a doubt on this piece of code from the function gfInvert of the pegwit algorithm that is executed the most of the time. There are two infinite loop that call each other. Through some printf we discovered that these loops call each other eight times and then the first one return.

How can I use #pragma rules in this case?

for (;;) {
if (f[0] == 1) {
assert (f[1] != 0);
gfSmallDiv (b, f[1]);
/* destroy potentially sensitive data: */
gfClear (c); gfClear (f); gfClear (g); x = j = alpha = 0;
return 0;
}
if (f[0] < g[0]) {
goto SWAP_FG;
}
SWAP_GF:
j = f[0] - g[0];
x = logt[f[f[0]]] - logt[g[g[0]]] + TOGGLE;
alpha = expt[x >= TOGGLE ? x - TOGGLE : x];
gfAddMul (f, alpha, j, g);
gfAddMul (b, alpha, j, c);
}

/* basically same code with b,c,f,g swapped */
for (;;) {
if (g[0] == 1) {
assert (g[1] != 0);
gfSmallDiv (c, g[1]);
gfCopy (b, c);
/* destroy potentially sensitive data: */
gfClear (c); gfClear (f); gfClear (g); x = j = alpha = 0;
return 0;
}
if (g[0] < f[0]) {
goto SWAP_GF;
}
SWAP_FG:
j = g[0] - f[0];
x = logt[g[g[0]]] - logt[f[f[0]]] + TOGGLE;
alpha = expt[x >= TOGGLE ? x - TOGGLE : x];
gfAddMul (g, alpha, j, f);
gfAddMul (c, alpha, j, b);
}
} /* gfInvert


Thanks,
Nicola



What #pragma are you planning to use, and what for?

-- Paolo
frb
 
Posts: 62
Joined: Thu Nov 12, 2009 3:44 pm

Re: loop optimization

Postby Guest » Thu Feb 23, 2006 8:37 pm

frb wrote:
nik wrote:hi,

I have a doubt on this piece of code from the function gfInvert of the pegwit algorithm that is executed the most of the time. There are two infinite loop that call each other. Through some printf we discovered that these loops call each other eight times and then the first one return.

How can I use #pragma rules in this case?

for (;;) {
if (f[0] == 1) {
assert (f[1] != 0);
gfSmallDiv (b, f[1]);
/* destroy potentially sensitive data: */
gfClear (c); gfClear (f); gfClear (g); x = j = alpha = 0;
return 0;
}
if (f[0] < g[0]) {
goto SWAP_FG;
}
SWAP_GF:
j = f[0] - g[0];
x = logt[f[f[0]]] - logt[g[g[0]]] + TOGGLE;
alpha = expt[x >= TOGGLE ? x - TOGGLE : x];
gfAddMul (f, alpha, j, g);
gfAddMul (b, alpha, j, c);
}

/* basically same code with b,c,f,g swapped */
for (;;) {
if (g[0] == 1) {
assert (g[1] != 0);
gfSmallDiv (c, g[1]);
gfCopy (b, c);
/* destroy potentially sensitive data: */
gfClear (c); gfClear (f); gfClear (g); x = j = alpha = 0;
return 0;
}
if (g[0] < f[0]) {
goto SWAP_GF;
}
SWAP_FG:
j = g[0] - f[0];
x = logt[g[g[0]]] - logt[f[f[0]]] + TOGGLE;
alpha = expt[x >= TOGGLE ? x - TOGGLE : x];
gfAddMul (g, alpha, j, f);
gfAddMul (c, alpha, j, b);
}
} /* gfInvert


Thanks,
Nicola



What #pragma are you planning to use, and what for?

-- Paolo


We made some proof for seeing the behaviour of these loops. Each loop cycles for two times and then go in the other loop. All of them are executed for 16 times. We have used the #pragma for loop unrolling but, how we thought, there are no improvements in the IPC.

Thanks,
Nicola
Guest
 


Return to VEX Tools



Who is online

Users browsing this forum: No registered users and 10 guests

cron