Search code examples
vhdlverilogsystem-verilog

In Verilog and VHDL, what exactly is the difference between `logic[19:4]` and `logic[15:0]`?


and of course the equivalent syntax in VHDL?

Is the lower index a minimum bound for indexing? What happens in assignments between signals with differing bounds but the same width?


Solution

  • Assuming you meant the widths to be the same...

    ...so, in Verilog let's assume you meant

    logic [19:4] v19_4;
    logic [15:0] v15_0;
    

    In a Verilog simulation, you will not experience any difference unless to try to index the bits.

    If you index the bits, you will find that

    • in the first case, the left hand bit is bit 19 (ie v19_4[19]), whereas in the second case, the left hand bit is bit 15 (ie v15_0[15]);

    • in the first case, the right hand bit is bit 4 (ie v19_4[4]), whereas in the second case, the right hand bit is bit 0 (ie v15_0[0]).

    In Verilog, it is valid to call the left hand bit "the MSB" and the right hand bit "the LSB".

    You will experience exactly the same behaviour in VHDL. In VHDL let's assume you meant

    signal v19_4 : std_logic_vector(19 downto 4);
    signal v15_0 : std_logic_vector(15 downto 0);
    

    Again, in a VHDL simulation, you will not experience any difference unless to try to index the bits. If you index the bits, you will find that

    • in the first case, the left hand bit is bit 19 (ie v19_4(19)), whereas in the second case, the left hand bit is bit 15 (ie v15_0(15));

    • in the first case, the right hand bit is bit 4 (ie v19_4(4)), whereas in the second case, the right hand bit is bit 0 (ie v15_0(0)).

    With synthesis you might see a difference. It is generally recommended to index vectors from 0 for synthesis to remove the possibility of synthesising more bits than you need. However, I would think that most synthesisers would optimise away the excess logic.