module popcount8 (
input [7:0] in,
output reg [3:0] count
);
integer i;
always @* begin
count = 4'd0;
for (i = 0; i < 8; i = i + 1) begin
count = count + in[i];
end
end
endmodule
for loops with constant bounds are compile-time unrolled into parallel hardware.always @* to avoid latch inference.int) and local to the block.