HDL & Verification

When the code above, which counts the 1s in 8-bit d, is synthesized, what kind of circuit results?

always @(*) begin
    count = 0;
    for (i = 0; i < 8; i = i + 1)
        count = count + d[i];
end
  1. AA sequential circuit counting one bit per clock over 8 cycles
  2. BThe loop is unrolled into eight steps, giving combinational logic with a chain of adders
  3. CFor loops cannot be synthesized, so it errors out
Show answer and explanation

Answer: B. The loop is unrolled into eight steps, giving combinational logic with a chain of adders

An HDL for loop does not reuse the same circuit repeatedly as software would; synthesis unrolls it into as many copies as there are iterations. Here it becomes combinational logic with eight adders in a row, computing everything within one clock. Many iterations make the circuit large and slow, so care is needed. To compute over time with less hardware, write a clocked state machine instead.

  • A. No clock is used, so it does not count over time.
  • B. Correct. The fixed iteration count allows unrolling.
  • C. For loops with fixed bounds are synthesizable.
Practice this topic Back to topic

More HDL & Verification questions

  1. What type of reset does the code above have, and how does it behave?
  2. What is the difference between synchronous and asynchronous resets?
  3. In circuits using asynchronous reset, why is reset release (the 0-to-1 transition) synchronized to the clock through two flip-flops before distribution?
  4. What is the basic structure of a state machine written in an HDL?
  5. In the state machine above, why does the second always block begin with "next = state;"?