A
Andy
Guest
On Jan 9, 3:23 am, Jonathan Bromley <jonathan.brom...@MYCOMPANY.com>
wrote:
index range of an array operand, just it's length? OUCH!!!
Overloading assignment operators could be very powerful!
Since resize() has a version where you pass it the target argument
itself for interrogation, instead of passing left and right indices,
it works similarly to your copy_v/s procedure, but with only one
function instead of two. Plus resize() can be used to control widths
(and therefore losses) in intermediate results of one expression.
I wonder if it would be better to overload all the operators to return
an intermediate type (and have overloaded versions to take
intermediate operands), but you would always declare your storage as
ufixed/sfixed. The only way to convert the intermediate type to the
ufixed/sfixed types is with a cast (at least you had to think about
it), or the resize() function, even if it really does not "resize"
anything. Or would such a system run into ambiguity problems with
expressions like a+b+c [(a+b)+c or a+(b+c)]?
In the final analysis, I agree that a standard package with a few
minor warts, with support from tool vendors, is better than a
"perfect" package with no support.
Andy
wrote:
So, what you're saying is that SV operators do not have access to theOn Tue, 8 Jan 2008 15:39:13 -0800 (PST),
Andy <jonesa...@comcast.net> wrote:
Is there no way to declare a new type that is another array of the
basic bit type in SV?
Yes, of course, but that new type would then be for all
practical purposes identical to a good old "reg [n-1:0]".
No distinction of integral types by their name.
As someone already pointed out, the only way to fix this
would be to create a struct of some kind - and ensure
that the scaling information, stored in an element of that
struct, was always used as a constant so that there would
be a reasonable chance of synthesis optimizing it away.
The only problem
[with the VHDL-200x fixed-point packages]
is that you can assign a ufixed(3 downto -4) to a
ufixed(4 downto -3), and it will take it with no errors, but the
results would not be arithmetically correct.
GRRRR, yes. The inability to overload or redefine
assignment in VHDL really comes back to bite us here.
For me, this almost completely undoes all the good work
of the fixed-point packages - it's so easy to break the
results in this way.
You almost always have to
use resize() to make sure the assignment is arithmetically correct
(with truncation/rounding, etc. if necessary).
Personally I see this as a significant weak spot in
the IEEE packages. When I did my own fixed-point
package, I "solved" this by creating a copy procedure
(actually two of them, one to copy to a variable and one
to copy to a signal). Procedures of course get to know
about their arguments' array attributes, and can do the
bit-tweaking automatically. So, for example, instead
of writing
target_variable := resize(a+b*c, target_variable'...);
one might write
Copy_V(target_variable, a+b*c);
where a,b,c are all fixed-point things of various
widths and scalings, and "target_variable" is
yet another. Rounding and truncation are defaulted in
the package (or use package generics in VHDL-2006) but
could also be supplied as optional arguments to Copy_V.
Copy_S (target_signal, ...) provided as a convenience.
Direct assignment to any variable or signal of floating-
point type is then outlawed (by convention) to avoid the
problem of accidental re-scaling.
Note, by the way, that I still support the IEEE standard
packages, which in all other respects are more complete
and better-debugged than mine were.
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.brom...@MYCOMPANY.comhttp://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
index range of an array operand, just it's length? OUCH!!!
Overloading assignment operators could be very powerful!
Since resize() has a version where you pass it the target argument
itself for interrogation, instead of passing left and right indices,
it works similarly to your copy_v/s procedure, but with only one
function instead of two. Plus resize() can be used to control widths
(and therefore losses) in intermediate results of one expression.
I wonder if it would be better to overload all the operators to return
an intermediate type (and have overloaded versions to take
intermediate operands), but you would always declare your storage as
ufixed/sfixed. The only way to convert the intermediate type to the
ufixed/sfixed types is with a cast (at least you had to think about
it), or the resize() function, even if it really does not "resize"
anything. Or would such a system run into ambiguity problems with
expressions like a+b+c [(a+b)+c or a+(b+c)]?
In the final analysis, I agree that a standard package with a few
minor warts, with support from tool vendors, is better than a
"perfect" package with no support.
Andy