On Sat, 19 Jan 2008 13:57:06 -0500, "KJ" wrote:
>> Yes, I know simulation will be a little slow
>> because of all the packing and unpacking of bits into
>> the complex data type
>Yet another alternative is to represent the complex as a single array of
>std_logic with one half dedicated to 'real', the other half to 'imaginary'.
>Now the 'Re' and 'Im' functions are simple one liners that strip out the
>appropriate range of bits. Both alternatives provide the same end user
>function of producing a complex type that can be of any size that does not
>need to be determined a priori.
Agreed.
>When debugging, both representations present a challenge for the user to
>assemble the bits into a complex number but the single vector approach would
>have a bit of an advantage
You're right. I hadn't really thought about that hard enough.
I was intending to provide a bunch of "to-string" conversions
(after the manner of std_logic_textio) and also some
non-synthesisable conversions to/from math_complex, to
make debugging and testbench reporting more convenient.
>Since the single vector representation concatenates two equally sized
>elements, what the user specifies for a 'width' is the total number of bits
>in the complex type (i.e. variable x: complex(15 downto 0) would be used to
>get 8 bit precision on the real and imaginary parts).
Yes. I must admit that I see that as a significant drawback,
but obviously it's fairly easy to deal with.
>Both should synthesize down to the same thing
>(but I haven't actually tested this).
I'd be amazed if it wasn't the case. My experience on my
fixed-point package (superseded by the IEEE one) was that
you can do quite complicated things with constants,
subscript calculations and so on, and synthesis will
simply do The Right Thing.
>The single vector representation might also be a good candidate for a
>protected type so that the user is completely insulated from details of the
>internal representation
I guess that would be true for either form...
> ...but I haven't tried synthesis tools on protected
>types yet.
I don't think protected types are, or were intended
to be, synthesisable.
>Putting your code into a loop for 2,000,000 iterations vsimk took 58
>seconds. Using the single vector representation the same number of loops
>took 19 seconds for a 3x sim time advantage.
Interesting, thanks for the experiment. I'm actually quite surprised
that the difference is so small; I'd have expected your representation
to be dramatically faster. I suspect the cost of the unsigned."+"
and unsigned."*" operations is swamping the effect of the
extract/compose functions; if you were to stub-out the complex
multiply with, for example, something that simply concatenated
the two operands:
return to_complex(Re(L) & Re(R), Im(L) & Im(R));
then you might more clearly see the performance hit from my
bit-pairs representation.
--
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
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.