Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how many "1" in input data?

Status
Not open for further replies.

vongy

Newbie level 6
Joined
Dec 12, 2006
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,351
please help me how to cacl the number ''1' in the input data in only one clock cycle?
for example:
if input [31:0] = 32'hf then output data = 4;
if input [31:0] = 32'7f then output data = 7;

please not use too many adder !
please not use for loop!

thanks
 

It's actually easy, but seems line a home work and I'll give you only a hint.
Draw a truth table of a full adder and look at it very carefully.
 

why not using loop & adder? easy to use and readable

variable_cnt := 0;
for i in 0 to 31 LOOP
if vector_input(i)='1' then
variable_cnt := variable_cnt + 1;
end if;
end for;
 

It's actually easy, but seems line a home work and I'll give you only a hint.
Draw a truth table of a full adder and look at it very carefully.

thanks, but it is not a homework!!!
I know i must use adder, but i want to use the least resource!!

---------- Post added at 04:12 ---------- Previous post was at 04:10 ----------

why not using loop & adder? easy to use and readable

variable_cnt := 0;
for i in 0 to 31 LOOP
if vector_input(i)='1' then
variable_cnt := variable_cnt + 1;
end if;
end for;

thanks.
Yes, this easy to readable, but it has 32 fulladder in series, how i can calc it in 5ns, my system run on 200MHz clock domain, and i must calc it in only one cycle!!
 

I told you what to do. Have you ever CAREFULLY and RIGOROUSLY looked at the truth table of full adder ?

Open your eyes real wide and look at the truth table. Doesn't notice anything ? if so, think about rearranging the table. Or better yet, consider what a binary full adder means mathematically.
Code:
A B Ci    S  Co
-----------------
0 0 0     0   0
0 0 1     1   0
0 1 0     1   0
0 1 1     0   1
1 0 0     1   0
1 0 1     0   1
1 1 0     0   1
1 1 1     1   1

This is one of weakness of today's digital engineer. They rely too much on RTLs and forgot the nature of binary operation.


PS. I quickly made a few logics. Apparently you need 4 adders to count 1 in 6 bits, 4 adders for 7 bits, 7 adders for 8 bits.. And it seem counting 1 in 32 bits requires 31 adders with only 8 levels of adders at the critical paths so that it will meet 5ns though I don't know which process you are using.
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top