Hi Forum members
I had a question regarding inferred latches in the design
If i have a code that counts the number of ones in a binary data sequence and I do
logic [31:0] sum;
always_comb begin
sum =0;
for(int i=0;i<DATA_WIDTH;i=i+1) begin
if(din[i])
sum = sum + din[i];
end
end
assign dout = sum;
Would a latch be inferred for sum for the case when din[i] !=1? Since sum is intended to hold its value till the loop runs through all the bits, should I use always_latch and sum <= sum + din[i] instead?
Thank you