Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - For..loop with variable range

 
Thread Tools Search this Thread
Old 11-30-2007, 12:28 AM   #1
Default For..loop with variable range



Hi,

I have this piece of code in my design:

function xxxxxx (...) is

[...]

for j in i to length - 1 loop
v(i) := '0';
end loop;

[...]

end xxxxxxx;

In this case 'i' is a variable, so I'm having problems syntesizing the
desing because the for..loop range is variable, not constant.

To make the context clear, the xxxxxx function converts a natural number to
a binary vector by making successive divisions. When the quotient is zero,
the for..loop fills the rest of the vector with 0's.

Any suggestion?

Thanks



Dan
  Reply With Quote
Old 11-30-2007, 03:24 AM   #2
KJ
 
Posts: n/a
Default Re: For..loop with variable range

"Dan" <> wrote in message
news:finlfc$6h0$...
>
> Hi,
>
> I have this piece of code in my design:
>

<snip>
> To make the context clear, the xxxxxx function converts a natural number
> to a binary vector by making successive divisions. When the quotient is
> zero, the for..loop fills the rest of the vector with 0's.
>
> Any suggestion?
>


Yes, don't reinvent the wheel, use the numeric_std package. Usage snippets
below.

use ieee.numeric_std.all;
.....
signal x: std_logic_vector(...);
signal y: natural range ...;
....
x <= std_logic_vector(to_unsigned(y, x'length));

KJ




KJ
  Reply With Quote
Old 11-30-2007, 02:39 PM   #3
Brian Drummond
 
Posts: n/a
Default Re: For..loop with variable range
On Fri, 30 Nov 2007 01:28:31 +0100, "Dan" <> wrote:

>
>Hi,
>
>I have this piece of code in my design:
>
>function xxxxxx (...) is
> for j in i to length - 1 loop
> v(i) := '0';
> end loop;
>end xxxxxxx;
>
>In this case 'i' is a variable, so I'm having problems syntesizing the
>desing because the for..loop range is variable, not constant.


You have to translate the algorithm into a synthesisable form; and that
means locally constant loop indices

> for j in thing'low to thing'high loop
>-- looping over all bits in "thing" whatever the range

or simply
> for j in 0 to length - 1 loop


Now you have to exclude the bits you don't want using realisable
hardware;
fortunately a comparison operator is realisable
> for j in 0 to length - 1 loop
> if j >= i then
> v(i) := '0';
> end if;


It clearly performs the same operation.
Incidentally did you mean v(j) := 0?

- Brian




Brian Drummond
  Reply With Quote
Old 12-03-2007, 02:40 PM   #4
Andy
 
Posts: n/a
Default Re: For..loop with variable range
On Nov 30, 8:39 am, Brian Drummond <brian_drumm...@btconnect.com>
wrote:
> On Fri, 30 Nov 2007 01:28:31 +0100, "Dan" <nom...@noserver.com> wrote:
>
> >Hi,

>
> >I have this piece of code in my design:

>
> >function xxxxxx (...) is
> > for j in i to length - 1 loop
> > v(i) := '0';
> > end loop;
> >end xxxxxxx;

>
> >In this case 'i' is a variable, so I'm having problems syntesizing the
> >desing because the for..loop range is variable, not constant.

>
> You have to translate the algorithm into a synthesisable form; and that
> means locally constant loop indices
>
>
>
> > for j in thing'low to thing'high loop
> >-- looping over all bits in "thing" whatever the range

> or simply
> > for j in 0 to length - 1 loop

>
> Now you have to exclude the bits you don't want using realisable
> hardware;
> fortunately a comparison operator is realisable
>
> > for j in 0 to length - 1 loop
> > if j >= i then
> > v(i) := '0';
> > end if;

>
> It clearly performs the same operation.
> Incidentally did you mean v(j) := 0?
>
> - Brian


Another way to get "variable index limit" on a for-loop is with an
exit statement to terminate the loop early. Put the exit statement in
a conditional inside the loop.

Andy


Andy
  Reply With Quote
Old 12-03-2007, 10:07 PM   #5
Brian Drummond
 
Posts: n/a
Default Re: For..loop with variable range
On Mon, 3 Dec 2007 06:40:33 -0800 (PST), Andy <>
wrote:

>On Nov 30, 8:39 am, Brian Drummond <brian_drumm...@btconnect.com>
>wrote:
>> On Fri, 30 Nov 2007 01:28:31 +0100, "Dan" <nom...@noserver.com> wrote:


>> > for j in 0 to length - 1 loop
>> > if j >= i then
>> > v(i) := '0';
>> > end if;


>Another way to get "variable index limit" on a for-loop is with an
>exit statement to terminate the loop early. Put the exit statement in
>a conditional inside the loop.


Good one, IF you can realise what you want by exiting early.

Does it synthesise as expected?

It's not so useful if you need a late entry to the loop, as the example
implies. In this case you can reverse the loop direction to get your
early exit, but if both ends were variables, it wouldn't work.

- Brian


Brian Drummond
  Reply With Quote
Old 12-04-2007, 12:43 AM   #6
Andy
 
Posts: n/a
Default Re: For..loop with variable range
On Dec 3, 4:07 pm, Brian Drummond <brian_drumm...@btconnect.com>
wrote:
> On Mon, 3 Dec 2007 06:40:33 -0800 (PST), Andy <jonesa...@comcast.net>
> wrote:
>
> >On Nov 30, 8:39 am, Brian Drummond <brian_drumm...@btconnect.com>
> >wrote:
> >> On Fri, 30 Nov 2007 01:28:31 +0100, "Dan" <nom...@noserver.com> wrote:
> >> > for j in 0 to length - 1 loop
> >> > if j >= i then
> >> > v(i) := '0';
> >> > end if;

> >Another way to get "variable index limit" on a for-loop is with an
> >exit statement to terminate the loop early. Put the exit statement in
> >a conditional inside the loop.

>
> Good one, IF you can realise what you want by exiting early.
>
> Does it synthesise as expected?
>
> It's not so useful if you need a late entry to the loop, as the example
> implies. In this case you can reverse the loop direction to get your
> early exit, but if both ends were variables, it wouldn't work.
>
> - Brian


Since a for-loop is unrolled in synthesis (that's the reason the index
bounds have to be static), a for-loop with a conditional unrolls to a
series of if-then statements (not nested). Putting an exit statement
in the conditional turns it into an if-elsif-elsif... sequence, so it
jumps to the end when a condition is hit.

Andy


Andy
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing value with out using variable in query string in PHP! Ali_ggl General Help Related Topics 0 11-29-2008 12:22 PM
synthesis error sekhar_kollati Hardware 0 11-13-2007 04:48 AM
Must declare the scalar variable "@Product_ID". iquad Software 0 11-10-2007 06:26 AM
Variable Scope in asp.Net jansi_rk Software 1 09-18-2006 06:05 PM
Re: Open Range DVD Review @ GENRE ONLINE.NET! Justin DVD Video 7 02-08-2004 06:50 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46