J
Jonathan Bromley
Guest
On Wed, 12 Jan 2005 00:31:40 +0100, Jan De Ceuster
<jan.de.ceuster@xs4all.be> wrote:
religious warfare.

or break the readability/maintainability of a piece of code.
Don't forget functions and procedures.
procedure Just_Copy_The_Damn_Bits_As_Unsigned_Binary (
signal S: out std_logic_vector;
N: in natural ) is
begin
S <= std_logic_vector ( to_unsigned ( N, S'length ) );
end;
...
JCTDBAUB ( counter , 1 ); -- Maintainable, clear, short
It is left as a trivial exercise for the reader to invent
a better name than JCTDBAUB for that procedure.
If you have a commonly-used subtype, it can be clearer to
use a function...
subtype Machine_Word is std_logic_vector(15 downto 0);
function to_Word ( N: in natural ) is
begin
return std_logic_vector (
to_unsigned ( N, Machine_Word'length ) );
end;
...
counter <= to_Word(1);
All these points are simple and obvious, but easy to
forget in the maelstrom of coding a significant design.
My golden rule is: as soon as I write a fragment of code
for the second time, it's a good moment to write a subprogram.
~~~~~~~~~~ end of sensible advice : start of rant ~~~~~~~~~~~
None of this alters the fact that the lack of assignment
overloading is a sad omission from VHDL. Obviously it's
made more difficult by the existence of two assignment
operators := and <= , but it seems to me that you don't
ever want to change the semantics of signal updating;
therefore, overloading := would be sufficient if you
accept that signal assignment is effectively a variable
assignment, to a hidden temporary variable of the same
subtype as the signal, followed by an update of the
signal using the value held in the hidden variable.
Fixed point arithmetic is an obvious example of a
situation where the lack of assignment overloading
is pretty much disastrous:
variable I: unsigned_fixed(3 downto 0); -- 4-bit integer
variable F: unsigned_fixed(-1 downto -4); -- 4-bit fraction
...
I := F; -- Ha ha, you inadvertently multiplied it by 16
-- and there's nothing the compiler can do to stop you!
--
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, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:jonathan.bromley@doulos.com
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.
<jan.de.ceuster@xs4all.be> wrote:
No, there's no overloading of assignment. A fine opportunity forI have a vector such as:
signal counter : unsigned(7 downto 0);
and want to set it to and integer (say 1). I have lots of cumbersome
ways to do it:
[snip]
What I would really like to do is overload assignment "<=" so I could
just write:
counter <= 1; -- My idea of elegant
but I don't think VHDL allows that
religious warfare.
You're entitled to your own opinionIt would be nice if VHDL had a "just copy the damn bits" assignment
operator, maybe call it "<-",
I think it's quite interesting; this kind of thing can makeOk, not the most interesting problem in the world, but VHDL type
conversion can be an awful pain at times.
or break the readability/maintainability of a piece of code.
Don't forget functions and procedures.
procedure Just_Copy_The_Damn_Bits_As_Unsigned_Binary (
signal S: out std_logic_vector;
N: in natural ) is
begin
S <= std_logic_vector ( to_unsigned ( N, S'length ) );
end;
...
JCTDBAUB ( counter , 1 ); -- Maintainable, clear, short
It is left as a trivial exercise for the reader to invent
a better name than JCTDBAUB for that procedure.
If you have a commonly-used subtype, it can be clearer to
use a function...
subtype Machine_Word is std_logic_vector(15 downto 0);
function to_Word ( N: in natural ) is
begin
return std_logic_vector (
to_unsigned ( N, Machine_Word'length ) );
end;
...
counter <= to_Word(1);
All these points are simple and obvious, but easy to
forget in the maelstrom of coding a significant design.
My golden rule is: as soon as I write a fragment of code
for the second time, it's a good moment to write a subprogram.
~~~~~~~~~~ end of sensible advice : start of rant ~~~~~~~~~~~
None of this alters the fact that the lack of assignment
overloading is a sad omission from VHDL. Obviously it's
made more difficult by the existence of two assignment
operators := and <= , but it seems to me that you don't
ever want to change the semantics of signal updating;
therefore, overloading := would be sufficient if you
accept that signal assignment is effectively a variable
assignment, to a hidden temporary variable of the same
subtype as the signal, followed by an update of the
signal using the value held in the hidden variable.
Fixed point arithmetic is an obvious example of a
situation where the lack of assignment overloading
is pretty much disastrous:
variable I: unsigned_fixed(3 downto 0); -- 4-bit integer
variable F: unsigned_fixed(-1 downto -4); -- 4-bit fraction
...
I := F; -- Ha ha, you inadvertently multiplied it by 16
-- and there's nothing the compiler can do to stop you!
--
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, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:jonathan.bromley@doulos.com
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.