declaring signals depending on generic parameters

V

valentin tihomirov

entity E is
SIZE: integer;
B : boolean;
end E;


The idea is to declare variable-length vector. Is wrapping the only solution
in VHDL?

architecture A of E is
signal S : std_logic_vector(B ? SIZE - 1: SIZE downto 0); -- C-like
ternary operators not supported

begin
...
 
J

Jonathan Bromley

valentin tihomirov said:
entity E is
SIZE: integer;
B : boolean;
end E;


The idea is to declare variable-length vector. Is wrapping the only solution
in VHDL?

architecture A of E is
signal S : std_logic_vector(B ? SIZE - 1: SIZE downto 0); -- C-like
ternary operators not supported

Don't forget that you can use any function to initialise a constant.

I'm assuming that SIZE and B are generics. It would be crazy
if they were ports, of course.

architecture A of E is

function bit_extended_size(N: integer; B: boolean) return integer is
begin
if B then
return N-1;
else
return N;
end if;
end;

constant W : integer := bit_extended_size(SIZE, B);

signal S: std_logic_vector(W downto 0);

--

Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail: (e-mail address removed)
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top