Search code examples
if-statementvhdl

VHDL synthesis of if statements without elsif and else condition


I am trying to understand better how synthesis works for a process like this one where no else conditions is specified.

I assume this is not the way to code because I am not considering other options but my question is how is going this code to be interpreted?

process(clock)
begin
if (clock'event and clock ='1') then 
  if sel0 = '1' then qout <= A - B;    end if; 
  if sel1 = '1' then qout <=  qout sra 2;        end if;
end if;
end process; 

IF statements are going to be synthesized into multiplexers. I think that for this example both the multiplexers are going to be connected together in a chain with a D register at the end for the registered value of out. I am guessing what is the value of qout when sel0 '0' and sel1 '0'? What happens to each multiplexer when its selector is '0'? Is the network keeping the same output, inferring a latch?

Thanks.


Solution

  • To show and learn how the synthesis tools implements the design, you can for example synthesize with Altera Quartus II and then use the build-in RTL viewer to show the high level representation of the resulting design.

    The code, using 1 bit vectors to simplify the structure, gives the result shown below.

    enter image description here

    So this shows a flip-flop that is updated every cycle, with value:

    • qout_sra_2 if sel1 = '1'
    • a_minus_b if sel1 = '0' and sel0 = '1'
    • qout (reassign with same value) if sel1 = '0' and sel0 = '0'

    Thus equivalent with:

    if clock'event and clock ='1' then 
      if sel1 = '1' then
        qout <= qout sra 2;
      elsif sel0 = '1' then
        qout <= A - B;
      else
        qout <= qout;
      end if; 
    end if;
    

    Other synthesis tools may implement it in a different, like Xilinx ISE that uses clock enable on the flip-flop, thus giving the result below.

    enter image description here

    So this shows a flip-flop that is updated if either sel0 or sel1 is '1', with value:

    • qout_sra_2 if sel1 = '1'
    • a_minus_b if sel1 = '0'

    Thus equivalent with:

    if clock'event and clock ='1' then 
      if not ((sel0 = '0') and (sel1 = '0')) then  -- (sel0 = '1') or (sel1 = '1')
        if sel1 = '1' then
          qout <= qout sra 2;
        else
          qout <= A - B;
        end if;
      end if;
    end if;