Traversing a vector counting zeros

U

Uwe Stange

Guest
Hi,

I encountered that traversing a vector bit by bit and incrementing a
counter for every zero found shows less performance than traversing
the vector in steps of two bit and adding 1 or 2 to the counter
depending on the bit pattern found.

Code snippet 1
--------------
for (i=0; i<=31; i=i+1)
if (vec_in == 1'b0)
counter = counter + 1'b1;


Code snippet 2
--------------
for (i=0; i<=30; i=i+2)
case( {vec_in[i+1],vec_in} )
2'b11: ;
2'b10: counter = counter + 1;
2'b01: counter = counter + 1;
2'b00: counter = counter + 2;
endcase


I'am 'measuring' performance in terms of estimated area, number of
nets and max path. Version 2 is at least 30% smaller/faster than
version 1. I do not know where such a big difference originates from.
Is this depending on the technology I am mapping to?

Any suggestions?

Bye! Uwe.
 
First of all, since you are incrementing by two in the second case,
the number of iterations is halved and there is your increase in
speed.
In terms of area decrease i think its the way the logic is
synthesized by the software you use to do so.
sachin


Uwe Stange <uwe.stange@freenet.de> wrote in message news:<lcq720dm9lu6evfmfuefk4mg2dofrurvu4@4ax.com>...
Hi,

I encountered that traversing a vector bit by bit and incrementing a
counter for every zero found shows less performance than traversing
the vector in steps of two bit and adding 1 or 2 to the counter
depending on the bit pattern found.

Code snippet 1
--------------
for (i=0; i<=31; i=i+1)
if (vec_in == 1'b0)
counter = counter + 1'b1;


Code snippet 2
--------------
for (i=0; i<=30; i=i+2)
case( {vec_in[i+1],vec_in} )
2'b11: ;
2'b10: counter = counter + 1;
2'b01: counter = counter + 1;
2'b00: counter = counter + 2;
endcase


I'am 'measuring' performance in terms of estimated area, number of
nets and max path. Version 2 is at least 30% smaller/faster than
version 1. I do not know where such a big difference originates from.
Is this depending on the technology I am mapping to?

Any suggestions?

Bye! Uwe.
 

Welcome to EDABoard.com

Sponsor

Back
Top