Mike,
>> For example if a variable is read before it is
>> written, it may create a register even when
>> that register is redundant.
>
> The implication is that using variables
> wastes flops, and this simply is not true.
Touchy are we
It only takes one counter case to prove this
statement wrong and I just showed you one.
> If the register is not intended,
> that is a design error like any
> other that would be picked up and corrected
> during the edit-sim-edit cycle.
> Is the wave correct or is it delayed by a tick?
The wave is correct - only one register in simulation.
Gate and RTL simulation match, yet the synthesis results
have 2 registers. If you look at the synthesis
results, you will see that both registers (VAR and Count)
have the same input - hence the tool did waste registers.
> The simulation results are what matters.
> Synthesis tools are very efficient with
> signals or variables.
With respect to registers, some synthesis tools
seem to be more generous producing registers than
others.
>> In the process below
>> sometimes VAR will create a register even though
>> that register has the same inputs as the Count
>> register:
>>
>> VarProc : Process
>> begin
>> wait until Clk = '1' ;
>> VAR := VAR + 1 ;
>> Count <= VAR ;
>> end process ;
>
> The error here is that the port
> assignment is inside a clocked clause.
> This infers an output pipeline register.
Nope. No extra pipeline delay.
BTW, this code is 1076.6-1999 and 1076.6-2004
compliant. As are results that produce either
one or two registers (the standard is about producing
results and not optimization).
> If I put the port assignment
> outside of the clocked clause,
> no pipeline register is inferred.
>
> clked : process(clk)
> variable cnt_v : count_t;
> begin
> if rising_edge(clk) then
> cnt_v := cnt_v + 1; -- increment on rising edge
> end if;
> cnt <= cnt_v; -- wire assignment outside of clocked clause
> end process clked;
>
The fact that you can fix the code is not the point.
The point is there is some code (not good code) that
looks fine, but will produce area inefficient results.
Also although you got results, is your code style portable?
In particular, does it work on Synopsys? I know they
did not support it in the past. Also it is not 1076.6-1999
compliant, it may not be 1076.6-2004 compliant either
(it certainly was not intended to be).
Cheers,
Jim
OTOH, so what if variables are inefficient with respect to
registers? Would you notice? Not unless you did not
fit in the chip.