How do I do a conditional statement in a constant statement?

T

tkvhdl

I'd like to do the equivalent of
constant X : integer = (A > B) ? A : B;
in VHDL, where A and B are either constants of generics
Obviously VHLD does not use the "?" operator, but I tried things such
as
constant X : integer = A when (A>B) else B;
and that doesn't work.
This is quite straightforward with Verilog Parameters so it is not
unreasonable to do this.
Is it possible in VHDL ?
 
M

Mike Treseler

I'd like to do the equivalent of
constant X : integer = (A > B) ? A : B;
Is it possible in VHDL ?

Yes, but I have to write the function myself:
function big_int (arg_a : integer;
arg_b : integer)
return integer is
begin
if arg_a > arg_b then
return arg_a;
else
return arg_b;
end if;
end function big_int;

constant X_c : integer := big_int(42,43);


-- Mike Treseler
 
A

allanherriman

I'd like to do the equivalent of
constant X : integer = (A > B) ? A : B;
in VHDL, where A and B are either constants of generics
Obviously VHLD does not use the "?" operator, but I tried things such
as
constant X : integer = A when (A>B) else B;
and that doesn't work.
This is quite straightforward with Verilog Parameters so it is not
unreasonable to do this.
Is it possible in VHDL ?

I believe this bug in the language will be fixed in VHDL-200x, proposal
FT10B. (I just read the document, and it's not quite clear whether
this will work for an initialiser in a declarative region. Hmmm.)

Until then, Mike's suggestion will work for you.

Regards,
Allan
 

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,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top