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

Discussion in 'VHDL' started by tkvhdl@gmail.com, Dec 15, 2005.

  1. Guest

    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 ?
    , Dec 15, 2005
    #1
    1. Advertising

  2. 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
    Mike Treseler, Dec 16, 2005
    #2
    1. Advertising

  3. Guest

    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
    , Dec 16, 2005
    #3
  4. Guest

    thanks.
    Glad to see this will be fixed in new VHDL!
    , Dec 16, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    2,764
  2. Alec S.
    Replies:
    10
    Views:
    10,091
    Alec S.
    Apr 16, 2005
  3. Sensorflo

    avoid constant conditional expression warning

    Sensorflo, Jan 7, 2004, in forum: C Programming
    Replies:
    2
    Views:
    515
    Derk Gwen
    Jan 7, 2004
  4. ramidamari

    conditional constant define

    ramidamari, Mar 11, 2008, in forum: VHDL
    Replies:
    0
    Views:
    605
    ramidamari
    Mar 11, 2008
  5. Fritz Bayer

    Conditional constant in regular expression

    Fritz Bayer, Apr 9, 2005, in forum: Perl Misc
    Replies:
    7
    Views:
    185
    Fritz Bayer
    Apr 10, 2005
Loading...

Share This Page