hdlbits-Popcount255

Popcount255

A "population count" circuit counts the number of '1's in an input vector. Build a population count circuit for a 255-bit input vector.

Hint

So many things to add... How about a for loop?

solution

1
2
3
4
5
6
7
8
9
10
module top_module( 
input [254:0] in,
output [7:0] out );
always @(*) begin
out = 0;
for (integer i=0;i<255;i++) begin
if (in[i]) out = out + 8'h01;
end
end
endmodule

hdlbits-Popcount255
http://456-xiao.github.io/2024/08/25/hdlbits-Popcount255/
作者
xyh
发布于
2024年8月25日
许可协议