Posts

Showing posts with the label verilog

Will temp variable in always_comb create latch

Image
Will temp variable in always_comb create latch I have following code snippet where a temp variable is used to count number of 1s in an array: // count the number 1s in array logic [5:0] count_v; //temp always_comb begin count_v = arr[0]; if (valid) begin for (int i=1; i<=31; i++) begin count_v = arr[i] + count_v; end end final_count = count_v; end Will this logic create a latch for count_v ? Is synthesis tool smart enough to properly synthesize this logic? I am struggling to find any coding recommendation for these kind of scenarios. Another example: logic temp; // temp variable always_comb begin temp = 0; for (int i=0; i<32; i++) begin if (i>=start) begin out_data[temp*8 +: 8] = in_data[i*8 +: 8]; temp = temp + 1'b1; end end end 3 Answers 3 General rule: if you read a variable befor...