Without using the $countones option or foreach, is there a way to count the number of 1s in a given binary number using only gates?
Thanks
Without using the $countones option or foreach, is there a way to count the number of 1s in a given binary number using only gates?
Thanks
In reply to UVM_learner6:
Without using the $countones option or foreach, is there a way to count the number of 1s in a given binary number using only gates?
An option is to use adders. Those adders can be a single thread (slow though) like
(((a[0]+a[1]) +a[2]) +a[3]) ...
Or with more parallelism
(a[0]+a[1]) (a[2]+a[3]) (a[4]+a[5]) (a[4]+a[5]) ...
_____|____________|_____ _____|___________|______
+ + + +
---------|-------- --------|-------
+ +
A synthesis tool should be able to do that for you automatically (e.g., use of the for loop. The style in writing the code may impact the speed, for example adding more parallelism). Pipeline regs will also speed things too.
Maybe there is a clever way to achieve this without clocking; for no this is my attmpted solution. I welcome ideas.
Ben Cohen
http://www.systemverilog.us/ ben@systemverilog.us
For training, consulting, services: contact Home - My cvcblr