SystemVerilog: how to achieve VHDL like unconstrained type b

A

Andrew

Guest
Hi,
I'm porting a VHDL function to a System Verilog testbench but I can't
see how to port an unconstrained input to SV?

The best I have come up with is to use a dynamic array:

function automatic void lfsr_shift ( bit polynomial[], //polynomial,
e.g. x^4 + x^3 + 1 = 4'b1100
ref bit lfsr_reg
[]); //pass in previous value of lfsr register here, new value
returned here.

But, I then don't know how to do a left shift operation on lfsr_reg.
The following gives an illegal reference to memory error:

lfsr_reg = lfsr_reg << 1;

Variable array indicies do not seem to be supported in SV (rather
surprising?) I.e. the following is not supported - array bounds must
be static.

lfsr_reg = {lfsr_reg[$left(lfsr_reg)-1:$right(lfsr_reg)],
lfsr_feedback};

Any ideas how I can workaround this? As a last resort I can write
loops, but that seems fairly ugly.

Cheers
Andrew
 
On Nov 10, 4:00 am, Andrew <andrew.brid...@gmail.com> wrote:
Hi,
I'm porting a VHDL function to a System Verilog testbench but I can't
see how to port an unconstrained input to SV?
Nope. Not directly, anyway. However, since you're
in testbench land you can probably use a queue.

, //polynomial,
e.g. x^4 + x^3 + 1 = 4'b1100
                                                  ref bit lfsr_reg
[]);   //pass in previous value of lfsr register here, new value
returned here.

But, I then don't know how to do a left shift operation on lfsr_reg.
The following gives an illegal reference to memory error:

lfsr_reg = lfsr_reg << 1;

Variable array indicies do not seem to be supported in SV (rather
surprising?) I.e. the following is not supported - array bounds must
be static.
Queues support shifting rather neatly:
Q = {Q[1:$], new_bit};

However, some tools don't support the {} queue-concat syntax
and you may need to do

bit Q[$]; // queue of bit
<compute new input bit, probably with a loop>
output_bit = Q.pop_front();
Q.push_back(new_bit);

You should be able to pass a queue as a ref argument to a function,
but if that fails you could pass it as an inout argument.

Shout if you need more details.
--
Jonathan Bromley
 
Generally I use dyn arrays for this but in this case JB is right, a
queue is more appropriate.
 
On Nov 11, 5:17 pm, SysTom wrote:

Generally I use dyn arrays for this
Interesting... In what way do you find dynamic
arrays more convenient than queues? I cannot think
of any situation in which a dynamic array is more
useful than a queue, except that you can size a
dyn-array in a single hit using new[] whereas
creating a queue with a given size is a little
harder (but usually it's unnecessary anyway).

I guess that there may be some rather small
performance penalty associated with queues
because of their more flexible insert/delete
facilities. Otherwise, though, I'd say that
queues are just plain better than dyn-arrays.

Just my $0.02.
--
Jonathan Bromley
 

Welcome to EDABoard.com

Sponsor

Back
Top