A constant with if-else-if

K

Kevin Neilson

How do I embed an if-else-if within a constant definition? This doesn't
compile in Modelsim:

constant Y : integer := A when A>B else B;

If I use the math_real library, I can do this:

constant Y : integer := integer(realmax(real(A),real(B)));

but I'd still like a general solution. Must I write a constant function?

-Kevin
 
K

KJ

Kevin Neilson said:
How do I embed an if-else-if within a constant definition? This doesn't
compile in Modelsim:

constant Y : integer := A when A>B else B;

If I use the math_real library, I can do this:

constant Y : integer := integer(realmax(real(A),real(B)));

but I'd still like a general solution. Must I write a constant function?

Yes, you have to write a function.

Kevin Jennings
 
A

Andy

How do I embed an if-else-if within a constant definition? This doesn't
compile in Modelsim:

constant Y : integer := A when A>B else B;

If I use the math_real library, I can do this:

constant Y : integer := integer(realmax(real(A),real(B)));

but I'd still like a general solution. Must I write a constant function?

-Kevin

Yes, a function would work, as would a secondary constant array,
indexed with boolean.

Andy
 
H

HT-Lab

Jim Lewis said:
The good news is that the functions maximum and minimum are
language defined in the Accellera VHDL-2006 / IEEE VHDL-2008 (yet
to be balloted) for all numeric (and scalar) types.

I would recommend submitting a bug report to the tool vendor
if they have not implemented them yet. Warning, if you don't
do this, then they think you are not interested in the new
standard.

I can't agree more with Jim, look at the supported language constructs and
you will soon agree with me that we need this standard ASAP!

Come on guys speak to your favourite EDA vendor/distributor and log an
Enhancement Request (ER) to have this standard supported. I have already
done this for Modelsim but it seems I am one of the few :-(

Hans
www.ht-lab.com
 
K

Kevin Neilson

Jim said:
The good news is that the functions maximum and minimum are
language defined in the Accellera VHDL-2006 / IEEE VHDL-2008 (yet
to be balloted) for all numeric (and scalar) types.

I would recommend submitting a bug report to the tool vendor
if they have not implemented them yet. Warning, if you don't
do this, then they think you are not interested in the new
standard.

Best,
Jim
I don't know if I'll waste the time. I started writing to vendors after
Verilog-2001 came out and the turn of the century was long forgotten
before any of those features (like generate) got implemented. I gather
that most coders write non-parameterizable highly structural code so
maybe the vendors don't need to support these constructs.

Besides, I want SystemVerilog to emerge as the winner, so I'm trying to
sabotage all other languages.
-Kevin
 
K

KJ

The Verilog construct is nice in these situations:

   parameter X = (A>B) ? A : B;

The VHDL construct is pretty nice too.

constant X: integer := maximum(A_scalar,B_scalar);
constant X: integer := maximum(A_vector);

I takes a couple minutes to write and test all the overloaded
'maximum' and 'minimum' functions that work with two arguments of all
the basic types or arrays of all the basic types.

KJ
 
G

Guest

I do have to use VHDL. I was just wishing I could do the Verilog thing,
with minimum verbosity.

Why the reluctance to write a function? I don't see how you can get
much
less verbose, or more self-evident, than
max(a,b)
and the function itself can be written just once, put in a package,
and used wherever you feel like it. "Verilog is less verbose than
VHDL"
is simply a myth.

Same deal for all the type conversions that people get so worked-up
about. If you find yourself using a particular type conversion more
than once, write a function to do it.
 
M

Mike Treseler

Kevin said:
I do have to use VHDL. I was just wishing I could do the Verilog thing,
with minimum verbosity.

I can hide verbosity, but not eliminate it,
by packaging functions and types that
do things my way. The upside is that this
is possible. The downside is that this
is sometimes necessary.

As far as the '?' function goes,
I can't improve on Jonathan's function.
But I happen to think that the unsweetened version,

if a>b then x:=a;
else x:=b;
end if;

has the verbosity about right
and is just as easy to read as

parameter X = (A>B) ? A : B;

-- Mike Treseler
 
K

KJ

I do have to use VHDL.  I was just wishing I could do the Verilog thing,
with minimum verbosity.

Even if you think use of the 'maximum' function is not adequate
because it is a specific case of your use of Verilog's '?' it is hard
to say that VHDL is more verbose with this syntax which is equivalent
to the Verilog '?'

X := sel(A>B, A, B);

It implies that you write once (and put it in your package of commonly
used VHDL helper functions) overloaded versions of the 'sel' function
that are of the form

function sel(Cond: BOOLEAN; A,B: integer) return integer;
function sel(Cond: BOOLEAN; A,B: real) return real;
function sel(Cond: BOOLEAN; A,B: time) return time;
function sel(Cond: BOOLEAN; A,B: std_logic) return std_logic;
...etc...

Kevin Jennings
 

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,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top