Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > How do I do a conditional statement in a constant statement?

Reply
Thread Tools

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

 
 
tkvhdl@gmail.com
Guest
Posts: n/a
 
      12-15-2005
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 ?

 
Reply With Quote
 
 
 
 
Mike Treseler
Guest
Posts: n/a
 
      12-16-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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
 
Reply With Quote
 
 
 
 
allanherriman@hotmail.com
Guest
Posts: n/a
 
      12-16-2005
(E-Mail Removed) wrote:
> 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

 
Reply With Quote
 
tkvhdl@gmail.com
Guest
Posts: n/a
 
      12-16-2005
thanks.
Glad to see this will be fixed in new VHDL!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
conditional constant define ramidamari VHDL 0 03-11-2008 10:33 AM
how to write a conditional assignment over generic or constant? sm.soimu@gmail.com VHDL 2 04-25-2006 10:00 AM
? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes Alec S. HTML 10 04-16-2005 02:21 AM
Conditional constant in regular expression Fritz Bayer Perl Misc 7 04-10-2005 09:43 AM
avoid constant conditional expression warning Sensorflo C Programming 2 01-07-2004 11:51 PM



Advertisments